@@ -202,7 +202,7 @@ type tNode struct {
202202
203203// untombed returns the S-node contained by the T-node.
204204func (t * tNode ) untombed () * sNode {
205- return & sNode {& entry { key : t .key , hash : t .hash , value : t .value }}
205+ return & sNode {& Entry { Key : t .Key , hash : t .hash , Value : t .Value }}
206206}
207207
208208// lNode is a list node which is a leaf node used to handle hashcode
@@ -219,25 +219,25 @@ func (l *lNode) entry() *sNode {
219219
220220// lookup returns the value at the given entry in the L-node or returns false
221221// if it's not contained.
222- func (l * lNode ) lookup (e * entry ) (interface {}, bool ) {
222+ func (l * lNode ) lookup (e * Entry ) (interface {}, bool ) {
223223 found , ok := l .Find (func (sn interface {}) bool {
224- return bytes .Equal (e .key , sn .(* sNode ).key )
224+ return bytes .Equal (e .Key , sn .(* sNode ).Key )
225225 })
226226 if ! ok {
227227 return nil , false
228228 }
229- return found .(* sNode ).value , true
229+ return found .(* sNode ).Value , true
230230}
231231
232232// inserted creates a new L-node with the added entry.
233- func (l * lNode ) inserted (entry * entry ) * lNode {
233+ func (l * lNode ) inserted (entry * Entry ) * lNode {
234234 return & lNode {l .Add (& sNode {entry })}
235235}
236236
237237// removed creates a new L-node with the entry removed.
238- func (l * lNode ) removed (e * entry ) * lNode {
238+ func (l * lNode ) removed (e * Entry ) * lNode {
239239 idx := l .FindIndex (func (sn interface {}) bool {
240- return bytes .Equal (e .key , sn .(* sNode ).key )
240+ return bytes .Equal (e .Key , sn .(* sNode ).Key )
241241 })
242242 if idx < 0 {
243243 return l
@@ -254,17 +254,16 @@ func (l *lNode) length() uint {
254254// branch is either an iNode or sNode.
255255type branch interface {}
256256
257- // entry contains a Ctrie entry, which is also a technique used to cache the
258- // hashcode of the key.
259- type entry struct {
260- key [] byte
257+ // Entry contains a Ctrie key-value pair.
258+ type Entry struct {
259+ Key [] byte
260+ Value interface {}
261261 hash uint32
262- value interface {}
263262}
264263
265264// sNode is a singleton node which contains a single key and value.
266265type sNode struct {
267- * entry
266+ * Entry
268267}
269268
270269// New creates an empty Ctrie which uses the provided HashFactory for key
@@ -294,24 +293,24 @@ func newCtrie(root *iNode, hashFactory HashFactory, readOnly bool) *Ctrie {
294293// the key already exists.
295294func (c * Ctrie ) Insert (key []byte , value interface {}) {
296295 c .assertReadWrite ()
297- c .insert (& entry {
298- key : key ,
296+ c .insert (& Entry {
297+ Key : key ,
298+ Value : value ,
299299 hash : c .hash (key ),
300- value : value ,
301300 })
302301}
303302
304303// Lookup returns the value for the associated key or returns false if the key
305304// doesn't exist.
306305func (c * Ctrie ) Lookup (key []byte ) (interface {}, bool ) {
307- return c .lookup (& entry { key : key , hash : c .hash (key )})
306+ return c .lookup (& Entry { Key : key , hash : c .hash (key )})
308307}
309308
310309// Remove deletes the value for the associated key, returning true if it was
311310// removed or false if the entry doesn't exist.
312311func (c * Ctrie ) Remove (key []byte ) (interface {}, bool ) {
313312 c .assertReadWrite ()
314- return c .remove (& entry { key : key , hash : c .hash (key )})
313+ return c .remove (& Entry { Key : key , hash : c .hash (key )})
315314}
316315
317316// Snapshot returns a stable, point-in-time snapshot of the Ctrie.
@@ -340,20 +339,22 @@ func (c *Ctrie) ReadOnlySnapshot() *Ctrie {
340339 }
341340}
342341
342+ //func (c *Ctrie) Iterator()
343+
343344func (c * Ctrie ) assertReadWrite () {
344345 if c .readOnly {
345346 panic ("Cannot modify read-only snapshot" )
346347 }
347348}
348349
349- func (c * Ctrie ) insert (entry * entry ) {
350+ func (c * Ctrie ) insert (entry * Entry ) {
350351 root := c .readRoot ()
351352 if ! c .iinsert (root , entry , 0 , nil , root .gen ) {
352353 c .insert (entry )
353354 }
354355}
355356
356- func (c * Ctrie ) lookup (entry * entry ) (interface {}, bool ) {
357+ func (c * Ctrie ) lookup (entry * Entry ) (interface {}, bool ) {
357358 root := c .readRoot ()
358359 result , exists , ok := c .ilookup (root , entry , 0 , nil , root .gen )
359360 for ! ok {
@@ -362,7 +363,7 @@ func (c *Ctrie) lookup(entry *entry) (interface{}, bool) {
362363 return result , exists
363364}
364365
365- func (c * Ctrie ) remove (entry * entry ) (interface {}, bool ) {
366+ func (c * Ctrie ) remove (entry * Entry ) (interface {}, bool ) {
366367 root := c .readRoot ()
367368 result , exists , ok := c .iremove (root , entry , 0 , nil , root .gen )
368369 for ! ok {
@@ -383,7 +384,7 @@ func (c *Ctrie) hash(k []byte) uint32 {
383384
384385// iinsert attempts to insert the entry into the Ctrie. If false is returned,
385386// the operation should be retried.
386- func (c * Ctrie ) iinsert (i * iNode , entry * entry , lev uint , parent * iNode , startGen * generation ) bool {
387+ func (c * Ctrie ) iinsert (i * iNode , entry * Entry , lev uint , parent * iNode , startGen * generation ) bool {
387388 // Linearization point.
388389 main := gcasRead (i , c )
389390 switch {
@@ -417,7 +418,7 @@ func (c *Ctrie) iinsert(i *iNode, entry *entry, lev uint, parent *iNode, startGe
417418 return false
418419 case * sNode :
419420 sn := branch .(* sNode )
420- if ! bytes .Equal (sn .key , entry .key ) {
421+ if ! bytes .Equal (sn .Key , entry .Key ) {
421422 // If the branch is an S-node and its key is not equal to the
422423 // key being inserted, then the Ctrie has to be extended with
423424 // an additional level. The C-node is replaced with its updated
@@ -457,7 +458,7 @@ func (c *Ctrie) iinsert(i *iNode, entry *entry, lev uint, parent *iNode, startGe
457458// values are the entry value and whether or not the entry was contained in the
458459// Ctrie. The last bool indicates if the operation succeeded. False means it
459460// should be retried.
460- func (c * Ctrie ) ilookup (i * iNode , entry * entry , lev uint , parent * iNode , startGen * generation ) (interface {}, bool , bool ) {
461+ func (c * Ctrie ) ilookup (i * iNode , entry * Entry , lev uint , parent * iNode , startGen * generation ) (interface {}, bool , bool ) {
461462 // Linearization point.
462463 main := gcasRead (i , c )
463464 switch {
@@ -490,8 +491,8 @@ func (c *Ctrie) ilookup(i *iNode, entry *entry, lev uint, parent *iNode, startGe
490491 // equal, the corresponding value from the S-node is
491492 // returned and a NOTFOUND value otherwise.
492493 sn := branch .(* sNode )
493- if bytes .Equal (sn .key , entry .key ) {
494- return sn .value , true , true
494+ if bytes .Equal (sn .Key , entry .Key ) {
495+ return sn .Value , true , true
495496 }
496497 return nil , false , true
497498 default :
@@ -513,7 +514,7 @@ func (c *Ctrie) ilookup(i *iNode, entry *entry, lev uint, parent *iNode, startGe
513514// values are the entry value and whether or not the entry was contained in the
514515// Ctrie. The last bool indicates if the operation succeeded. False means it
515516// should be retried.
516- func (c * Ctrie ) iremove (i * iNode , entry * entry , lev uint , parent * iNode , startGen * generation ) (interface {}, bool , bool ) {
517+ func (c * Ctrie ) iremove (i * iNode , entry * Entry , lev uint , parent * iNode , startGen * generation ) (interface {}, bool , bool ) {
517518 // Linearization point.
518519 main := gcasRead (i , c )
519520 switch {
@@ -543,7 +544,7 @@ func (c *Ctrie) iremove(i *iNode, entry *entry, lev uint, parent *iNode, startGe
543544 // If the branch is an S-node, its key is compared against the key
544545 // being removed.
545546 sn := branch .(* sNode )
546- if ! bytes .Equal (sn .key , entry .key ) {
547+ if ! bytes .Equal (sn .Key , entry .Key ) {
547548 // If the keys are not equal, the NOTFOUND value is returned.
548549 return nil , false , true
549550 }
@@ -562,7 +563,7 @@ func (c *Ctrie) iremove(i *iNode, entry *entry, lev uint, parent *iNode, startGe
562563 cleanParent (parent , i , entry .hash , lev - w , c , startGen )
563564 }
564565 }
565- return sn .value , true , true
566+ return sn .Value , true , true
566567 }
567568 return nil , false , false
568569 default :
@@ -642,13 +643,13 @@ func clean(i *iNode, lev uint, ctrie *Ctrie) bool {
642643 return true
643644}
644645
645- func cleanReadOnly (tn * tNode , lev uint , p * iNode , ctrie * Ctrie , entry * entry ) (val interface {}, exists bool , ok bool ) {
646+ func cleanReadOnly (tn * tNode , lev uint , p * iNode , ctrie * Ctrie , entry * Entry ) (val interface {}, exists bool , ok bool ) {
646647 if ! ctrie .readOnly {
647648 clean (p , lev - 5 , ctrie )
648649 return nil , false , false
649650 }
650- if tn .hash == entry .hash && bytes .Equal (tn .key , entry .key ) {
651- return tn .value , true , true
651+ if tn .hash == entry .hash && bytes .Equal (tn .Key , entry .Key ) {
652+ return tn .Value , true , true
652653 }
653654 return nil , false , true
654655}
0 commit comments