File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -350,6 +350,15 @@ func (c *Ctrie) Iterator() <-chan *Entry {
350350 return ch
351351}
352352
353+ // Size returns the number of keys in the Ctrie.
354+ func (c * Ctrie ) Size () uint {
355+ size := uint (0 )
356+ for _ = range c .Iterator () {
357+ size ++
358+ }
359+ return size
360+ }
361+
353362func traverse (i * iNode , ch chan <- * Entry ) {
354363 switch {
355364 case i .main .cNode != nil :
Original file line number Diff line number Diff line change @@ -283,6 +283,14 @@ func TestIterator(t *testing.T) {
283283 assert .Equal (len (expected ), count )
284284}
285285
286+ func TestSize (t * testing.T ) {
287+ ctrie := New (nil )
288+ for i := 0 ; i < 10 ; i ++ {
289+ ctrie .Insert ([]byte (strconv .Itoa (i )), i )
290+ }
291+ assert .Equal (t , uint (10 ), ctrie .Size ())
292+ }
293+
286294func BenchmarkInsert (b * testing.B ) {
287295 ctrie := New (nil )
288296 b .ResetTimer ()
You can’t perform that action at this time.
0 commit comments