OLD | NEW |
1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 // Package treapstore is a lightweight append-only in-memory key-value store | 5 // Package treapstore is a lightweight append-only in-memory key-value store |
6 // built on top a treap (tree + heap) implementation. | 6 // built on top a treap (tree + heap) implementation. |
7 // | 7 // |
8 // treapstore is specifically focused on supporting the in-memory datastore | 8 // treapstore is specifically focused on supporting the in-memory datastore |
9 // implementation at "github.com/luci/gae/impl/memory". | 9 // implementation at "github.com/luci/gae/impl/memory". |
10 package treapstore | 10 package treapstore |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 } | 230 } |
231 | 231 |
232 func (c *Collection) setRoot(root *gtreap.Treap) { | 232 func (c *Collection) setRoot(root *gtreap.Treap) { |
233 if c.rootLock != nil { | 233 if c.rootLock != nil { |
234 c.rootLock.Lock() | 234 c.rootLock.Lock() |
235 defer c.rootLock.Unlock() | 235 defer c.rootLock.Unlock() |
236 } | 236 } |
237 c.root = root | 237 c.root = root |
238 } | 238 } |
239 | 239 |
240 // Iterator returns an iterator over the Store, starting at the supplied pivot | 240 // VisitAscend traverses the Collection ascendingly, invoking visitor for each |
241 // item. | 241 // visited item. |
| 242 // |
| 243 // If visitor returns false, iteration will stop prematurely. |
| 244 // |
| 245 // VisitAscend is a more efficient traversal than using an Iterator, and is |
| 246 // useful in times when entry-by-entry iteration is not required. |
| 247 func (c *Collection) VisitAscend(pivot gtreap.Item, visitor gtreap.ItemVisitor)
{ |
| 248 » c.currentRoot().VisitAscend(pivot, visitor) |
| 249 } |
| 250 |
| 251 // Iterator returns an iterator over the Collection, starting at the supplied |
| 252 // pivot item. |
242 func (c *Collection) Iterator(pivot gtreap.Item) *gtreap.Iterator { | 253 func (c *Collection) Iterator(pivot gtreap.Item) *gtreap.Iterator { |
243 root := c.currentRoot() | 254 root := c.currentRoot() |
244 if root == nil { | 255 if root == nil { |
245 root = emptyTreap | 256 root = emptyTreap |
246 } | 257 } |
247 return root.Iterator(pivot) | 258 return root.Iterator(pivot) |
248 } | 259 } |
OLD | NEW |