gitee.com/quant1x/gox@v1.21.2/util/avltree/avltree_test.go (about)

     1  // Use of this source code is governed by a BSD-style
     2  // license that can be found in the LICENSE file.
     3  
     4  package avltree
     5  
     6  import (
     7  	"fmt"
     8  	"testing"
     9  )
    10  
    11  func TestAVLTreePut(t *testing.T) {
    12  	tree := NewWithIntComparator()
    13  	tree.Put(5, "e")
    14  	tree.Put(6, "f")
    15  	tree.Put(7, "g")
    16  	tree.Put(3, "c")
    17  	tree.Put(4, "d")
    18  	tree.Put(1, "x")
    19  	tree.Put(2, "b")
    20  	tree.Put(1, "a") //overwrite
    21  
    22  	if actualValue := tree.Size(); actualValue != 7 {
    23  		t.Errorf("Got %v expected %v", actualValue, 7)
    24  	}
    25  	if actualValue, expectedValue := fmt.Sprintf("%d%d%d%d%d%d%d", tree.Keys()...), "1234567"; actualValue != expectedValue {
    26  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
    27  	}
    28  	if actualValue, expectedValue := fmt.Sprintf("%s%s%s%s%s%s%s", tree.Values()...), "abcdefg"; actualValue != expectedValue {
    29  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
    30  	}
    31  
    32  	tests1 := [][]interface{}{
    33  		{1, "a", true},
    34  		{2, "b", true},
    35  		{3, "c", true},
    36  		{4, "d", true},
    37  		{5, "e", true},
    38  		{6, "f", true},
    39  		{7, "g", true},
    40  		{8, nil, false},
    41  	}
    42  
    43  	for _, test := range tests1 {
    44  		// retrievals
    45  		actualValue, actualFound := tree.Get(test[0])
    46  		if actualValue != test[1] || actualFound != test[2] {
    47  			t.Errorf("Got %v expected %v", actualValue, test[1])
    48  		}
    49  	}
    50  }
    51  
    52  func TestAVLTreeRemove(t *testing.T) {
    53  	tree := NewWithIntComparator()
    54  	tree.Put(5, "e")
    55  	tree.Put(6, "f")
    56  	tree.Put(7, "g")
    57  	tree.Put(3, "c")
    58  	tree.Put(4, "d")
    59  	tree.Put(1, "x")
    60  	tree.Put(2, "b")
    61  	tree.Put(1, "a") //overwrite
    62  
    63  	tree.Remove(5)
    64  	tree.Remove(6)
    65  	tree.Remove(7)
    66  	tree.Remove(8)
    67  	tree.Remove(5)
    68  
    69  	if actualValue, expectedValue := fmt.Sprintf("%d%d%d%d", tree.Keys()...), "1234"; actualValue != expectedValue {
    70  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
    71  	}
    72  	if actualValue, expectedValue := fmt.Sprintf("%s%s%s%s", tree.Values()...), "abcd"; actualValue != expectedValue {
    73  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
    74  	}
    75  	if actualValue, expectedValue := fmt.Sprintf("%s%s%s%s", tree.Values()...), "abcd"; actualValue != expectedValue {
    76  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
    77  	}
    78  	if actualValue := tree.Size(); actualValue != 4 {
    79  		t.Errorf("Got %v expected %v", actualValue, 7)
    80  	}
    81  
    82  	tests2 := [][]interface{}{
    83  		{1, "a", true},
    84  		{2, "b", true},
    85  		{3, "c", true},
    86  		{4, "d", true},
    87  		{5, nil, false},
    88  		{6, nil, false},
    89  		{7, nil, false},
    90  		{8, nil, false},
    91  	}
    92  
    93  	for _, test := range tests2 {
    94  		actualValue, actualFound := tree.Get(test[0])
    95  		if actualValue != test[1] || actualFound != test[2] {
    96  			t.Errorf("Got %v expected %v", actualValue, test[1])
    97  		}
    98  	}
    99  
   100  	tree.Remove(1)
   101  	tree.Remove(4)
   102  	tree.Remove(2)
   103  	tree.Remove(3)
   104  	tree.Remove(2)
   105  	tree.Remove(2)
   106  
   107  	if actualValue, expectedValue := fmt.Sprintf("%s", tree.Keys()), "[]"; actualValue != expectedValue {
   108  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
   109  	}
   110  	if actualValue, expectedValue := fmt.Sprintf("%s", tree.Values()), "[]"; actualValue != expectedValue {
   111  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
   112  	}
   113  	if empty, size := tree.Empty(), tree.Size(); empty != true || size != -0 {
   114  		t.Errorf("Got %v expected %v", empty, true)
   115  	}
   116  
   117  }
   118  
   119  func TestAVLTreeLeftAndRight(t *testing.T) {
   120  	tree := NewWithIntComparator()
   121  
   122  	if actualValue := tree.Left(); actualValue != nil {
   123  		t.Errorf("Got %v expected %v", actualValue, nil)
   124  	}
   125  	if actualValue := tree.Right(); actualValue != nil {
   126  		t.Errorf("Got %v expected %v", actualValue, nil)
   127  	}
   128  
   129  	tree.Put(1, "a")
   130  	tree.Put(5, "e")
   131  	tree.Put(6, "f")
   132  	tree.Put(7, "g")
   133  	tree.Put(3, "c")
   134  	tree.Put(4, "d")
   135  	tree.Put(1, "x") // overwrite
   136  	tree.Put(2, "b")
   137  
   138  	if actualValue, expectedValue := fmt.Sprintf("%d", tree.Left().Key), "1"; actualValue != expectedValue {
   139  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
   140  	}
   141  	if actualValue, expectedValue := fmt.Sprintf("%s", tree.Left().Value), "x"; actualValue != expectedValue {
   142  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
   143  	}
   144  
   145  	if actualValue, expectedValue := fmt.Sprintf("%d", tree.Right().Key), "7"; actualValue != expectedValue {
   146  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
   147  	}
   148  	if actualValue, expectedValue := fmt.Sprintf("%s", tree.Right().Value), "g"; actualValue != expectedValue {
   149  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
   150  	}
   151  }
   152  
   153  func TestAVLTreeCeilingAndFloor(t *testing.T) {
   154  	tree := NewWithIntComparator()
   155  
   156  	if node, found := tree.Floor(0); node != nil || found {
   157  		t.Errorf("Got %v expected %v", node, "<nil>")
   158  	}
   159  	if node, found := tree.Ceiling(0); node != nil || found {
   160  		t.Errorf("Got %v expected %v", node, "<nil>")
   161  	}
   162  
   163  	tree.Put(5, "e")
   164  	tree.Put(6, "f")
   165  	tree.Put(7, "g")
   166  	tree.Put(3, "c")
   167  	tree.Put(4, "d")
   168  	tree.Put(1, "x")
   169  	tree.Put(2, "b")
   170  
   171  	if node, found := tree.Floor(4); node.Key != 4 || !found {
   172  		t.Errorf("Got %v expected %v", node.Key, 4)
   173  	}
   174  	if node, found := tree.Floor(0); node != nil || found {
   175  		t.Errorf("Got %v expected %v", node, "<nil>")
   176  	}
   177  
   178  	if node, found := tree.Ceiling(4); node.Key != 4 || !found {
   179  		t.Errorf("Got %v expected %v", node.Key, 4)
   180  	}
   181  	if node, found := tree.Ceiling(8); node != nil || found {
   182  		t.Errorf("Got %v expected %v", node, "<nil>")
   183  	}
   184  }
   185  
   186  func TestAVLTreeIteratorNextOnEmpty(t *testing.T) {
   187  	tree := NewWithIntComparator()
   188  	it := tree.Iterator()
   189  	for it.Next() {
   190  		t.Errorf("Shouldn't iterate on empty tree")
   191  	}
   192  }
   193  
   194  func TestAVLTreeIteratorPrevOnEmpty(t *testing.T) {
   195  	tree := NewWithIntComparator()
   196  	it := tree.Iterator()
   197  	for it.Prev() {
   198  		t.Errorf("Shouldn't iterate on empty tree")
   199  	}
   200  }
   201  
   202  func TestAVLTreeIterator1Next(t *testing.T) {
   203  	tree := NewWithIntComparator()
   204  	tree.Put(5, "e")
   205  	tree.Put(6, "f")
   206  	tree.Put(7, "g")
   207  	tree.Put(3, "c")
   208  	tree.Put(4, "d")
   209  	tree.Put(1, "x")
   210  	tree.Put(2, "b")
   211  	tree.Put(1, "a") //overwrite
   212  	// │   ┌── 7
   213  	// └── 6
   214  	//     │   ┌── 5
   215  	//     └── 4
   216  	//         │   ┌── 3
   217  	//         └── 2
   218  	//             └── 1
   219  	it := tree.Iterator()
   220  	count := 0
   221  	for it.Next() {
   222  		count++
   223  		key := it.Key()
   224  		switch key {
   225  		case count:
   226  			if actualValue, expectedValue := key, count; actualValue != expectedValue {
   227  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   228  			}
   229  		default:
   230  			if actualValue, expectedValue := key, count; actualValue != expectedValue {
   231  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   232  			}
   233  		}
   234  	}
   235  	if actualValue, expectedValue := count, tree.Size(); actualValue != expectedValue {
   236  		t.Errorf("Size different. Got %v expected %v", actualValue, expectedValue)
   237  	}
   238  }
   239  
   240  func TestAVLTreeIterator1Prev(t *testing.T) {
   241  	tree := NewWithIntComparator()
   242  	tree.Put(5, "e")
   243  	tree.Put(6, "f")
   244  	tree.Put(7, "g")
   245  	tree.Put(3, "c")
   246  	tree.Put(4, "d")
   247  	tree.Put(1, "x")
   248  	tree.Put(2, "b")
   249  	tree.Put(1, "a") //overwrite
   250  	// │   ┌── 7
   251  	// └── 6
   252  	//     │   ┌── 5
   253  	//     └── 4
   254  	//         │   ┌── 3
   255  	//         └── 2
   256  	//             └── 1
   257  	it := tree.Iterator()
   258  	for it.Next() {
   259  	}
   260  	countDown := tree.size
   261  	for it.Prev() {
   262  		key := it.Key()
   263  		switch key {
   264  		case countDown:
   265  			if actualValue, expectedValue := key, countDown; actualValue != expectedValue {
   266  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   267  			}
   268  		default:
   269  			if actualValue, expectedValue := key, countDown; actualValue != expectedValue {
   270  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   271  			}
   272  		}
   273  		countDown--
   274  	}
   275  	if actualValue, expectedValue := countDown, 0; actualValue != expectedValue {
   276  		t.Errorf("Size different. Got %v expected %v", actualValue, expectedValue)
   277  	}
   278  }
   279  
   280  func TestAVLTreeIterator2Next(t *testing.T) {
   281  	tree := NewWithIntComparator()
   282  	tree.Put(3, "c")
   283  	tree.Put(1, "a")
   284  	tree.Put(2, "b")
   285  	it := tree.Iterator()
   286  	count := 0
   287  	for it.Next() {
   288  		count++
   289  		key := it.Key()
   290  		switch key {
   291  		case count:
   292  			if actualValue, expectedValue := key, count; actualValue != expectedValue {
   293  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   294  			}
   295  		default:
   296  			if actualValue, expectedValue := key, count; actualValue != expectedValue {
   297  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   298  			}
   299  		}
   300  	}
   301  	if actualValue, expectedValue := count, tree.Size(); actualValue != expectedValue {
   302  		t.Errorf("Size different. Got %v expected %v", actualValue, expectedValue)
   303  	}
   304  }
   305  
   306  func TestAVLTreeIterator2Prev(t *testing.T) {
   307  	tree := NewWithIntComparator()
   308  	tree.Put(3, "c")
   309  	tree.Put(1, "a")
   310  	tree.Put(2, "b")
   311  	it := tree.Iterator()
   312  	for it.Next() {
   313  	}
   314  	countDown := tree.size
   315  	for it.Prev() {
   316  		key := it.Key()
   317  		switch key {
   318  		case countDown:
   319  			if actualValue, expectedValue := key, countDown; actualValue != expectedValue {
   320  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   321  			}
   322  		default:
   323  			if actualValue, expectedValue := key, countDown; actualValue != expectedValue {
   324  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   325  			}
   326  		}
   327  		countDown--
   328  	}
   329  	if actualValue, expectedValue := countDown, 0; actualValue != expectedValue {
   330  		t.Errorf("Size different. Got %v expected %v", actualValue, expectedValue)
   331  	}
   332  }
   333  
   334  func TestAVLTreeIterator3Next(t *testing.T) {
   335  	tree := NewWithIntComparator()
   336  	tree.Put(1, "a")
   337  	it := tree.Iterator()
   338  	count := 0
   339  	for it.Next() {
   340  		count++
   341  		key := it.Key()
   342  		switch key {
   343  		case count:
   344  			if actualValue, expectedValue := key, count; actualValue != expectedValue {
   345  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   346  			}
   347  		default:
   348  			if actualValue, expectedValue := key, count; actualValue != expectedValue {
   349  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   350  			}
   351  		}
   352  	}
   353  	if actualValue, expectedValue := count, tree.Size(); actualValue != expectedValue {
   354  		t.Errorf("Size different. Got %v expected %v", actualValue, expectedValue)
   355  	}
   356  }
   357  
   358  func TestAVLTreeIterator3Prev(t *testing.T) {
   359  	tree := NewWithIntComparator()
   360  	tree.Put(1, "a")
   361  	it := tree.Iterator()
   362  	for it.Next() {
   363  	}
   364  	countDown := tree.size
   365  	for it.Prev() {
   366  		key := it.Key()
   367  		switch key {
   368  		case countDown:
   369  			if actualValue, expectedValue := key, countDown; actualValue != expectedValue {
   370  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   371  			}
   372  		default:
   373  			if actualValue, expectedValue := key, countDown; actualValue != expectedValue {
   374  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   375  			}
   376  		}
   377  		countDown--
   378  	}
   379  	if actualValue, expectedValue := countDown, 0; actualValue != expectedValue {
   380  		t.Errorf("Size different. Got %v expected %v", actualValue, expectedValue)
   381  	}
   382  }
   383  
   384  func TestAVLTreeIterator4Next(t *testing.T) {
   385  	tree := NewWithIntComparator()
   386  	tree.Put(13, 5)
   387  	tree.Put(8, 3)
   388  	tree.Put(17, 7)
   389  	tree.Put(1, 1)
   390  	tree.Put(11, 4)
   391  	tree.Put(15, 6)
   392  	tree.Put(25, 9)
   393  	tree.Put(6, 2)
   394  	tree.Put(22, 8)
   395  	tree.Put(27, 10)
   396  	// │           ┌── 27
   397  	// │       ┌── 25
   398  	// │       │   └── 22
   399  	// │   ┌── 17
   400  	// │   │   └── 15
   401  	// └── 13
   402  	//     │   ┌── 11
   403  	//     └── 8
   404  	//         │   ┌── 6
   405  	//         └── 1
   406  	it := tree.Iterator()
   407  	count := 0
   408  	for it.Next() {
   409  		count++
   410  		value := it.Value()
   411  		switch value {
   412  		case count:
   413  			if actualValue, expectedValue := value, count; actualValue != expectedValue {
   414  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   415  			}
   416  		default:
   417  			if actualValue, expectedValue := value, count; actualValue != expectedValue {
   418  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   419  			}
   420  		}
   421  	}
   422  	if actualValue, expectedValue := count, tree.Size(); actualValue != expectedValue {
   423  		t.Errorf("Size different. Got %v expected %v", actualValue, expectedValue)
   424  	}
   425  }
   426  
   427  func TestAVLTreeIterator4Prev(t *testing.T) {
   428  	tree := NewWithIntComparator()
   429  	tree.Put(13, 5)
   430  	tree.Put(8, 3)
   431  	tree.Put(17, 7)
   432  	tree.Put(1, 1)
   433  	tree.Put(11, 4)
   434  	tree.Put(15, 6)
   435  	tree.Put(25, 9)
   436  	tree.Put(6, 2)
   437  	tree.Put(22, 8)
   438  	tree.Put(27, 10)
   439  	// │           ┌── 27
   440  	// │       ┌── 25
   441  	// │       │   └── 22
   442  	// │   ┌── 17
   443  	// │   │   └── 15
   444  	// └── 13
   445  	//     │   ┌── 11
   446  	//     └── 8
   447  	//         │   ┌── 6
   448  	//         └── 1
   449  	it := tree.Iterator()
   450  	count := tree.Size()
   451  	for it.Next() {
   452  	}
   453  	for it.Prev() {
   454  		value := it.Value()
   455  		switch value {
   456  		case count:
   457  			if actualValue, expectedValue := value, count; actualValue != expectedValue {
   458  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   459  			}
   460  		default:
   461  			if actualValue, expectedValue := value, count; actualValue != expectedValue {
   462  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   463  			}
   464  		}
   465  		count--
   466  	}
   467  	if actualValue, expectedValue := count, 0; actualValue != expectedValue {
   468  		t.Errorf("Size different. Got %v expected %v", actualValue, expectedValue)
   469  	}
   470  }
   471  
   472  func TestAVLTreeIteratorBegin(t *testing.T) {
   473  	tree := NewWithIntComparator()
   474  	tree.Put(3, "c")
   475  	tree.Put(1, "a")
   476  	tree.Put(2, "b")
   477  	it := tree.Iterator()
   478  
   479  	if it.Key() != nil {
   480  		t.Errorf("Got %v expected %v", it.Key(), nil)
   481  	}
   482  
   483  	it.Begin()
   484  
   485  	if it.Key() != nil {
   486  		t.Errorf("Got %v expected %v", it.Key(), nil)
   487  	}
   488  
   489  	for it.Next() {
   490  	}
   491  
   492  	it.Begin()
   493  
   494  	if it.Key() != nil {
   495  		t.Errorf("Got %v expected %v", it.Key(), nil)
   496  	}
   497  
   498  	it.Next()
   499  	if key, value := it.Key(), it.Value(); key != 1 || value != "a" {
   500  		t.Errorf("Got %v,%v expected %v,%v", key, value, 1, "a")
   501  	}
   502  }
   503  
   504  func TestAVLTreeIteratorEnd(t *testing.T) {
   505  	tree := NewWithIntComparator()
   506  	it := tree.Iterator()
   507  
   508  	if it.Key() != nil {
   509  		t.Errorf("Got %v expected %v", it.Key(), nil)
   510  	}
   511  
   512  	it.End()
   513  	if it.Key() != nil {
   514  		t.Errorf("Got %v expected %v", it.Key(), nil)
   515  	}
   516  
   517  	tree.Put(3, "c")
   518  	tree.Put(1, "a")
   519  	tree.Put(2, "b")
   520  	it.End()
   521  	if it.Key() != nil {
   522  		t.Errorf("Got %v expected %v", it.Key(), nil)
   523  	}
   524  
   525  	it.Prev()
   526  	if key, value := it.Key(), it.Value(); key != 3 || value != "c" {
   527  		t.Errorf("Got %v,%v expected %v,%v", key, value, 3, "c")
   528  	}
   529  }
   530  
   531  func TestAVLTreeIteratorFirst(t *testing.T) {
   532  	tree := NewWithIntComparator()
   533  	tree.Put(3, "c")
   534  	tree.Put(1, "a")
   535  	tree.Put(2, "b")
   536  	it := tree.Iterator()
   537  	if actualValue, expectedValue := it.First(), true; actualValue != expectedValue {
   538  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
   539  	}
   540  	if key, value := it.Key(), it.Value(); key != 1 || value != "a" {
   541  		t.Errorf("Got %v,%v expected %v,%v", key, value, 1, "a")
   542  	}
   543  }
   544  
   545  func TestAVLTreeIteratorLast(t *testing.T) {
   546  	tree := NewWithIntComparator()
   547  	tree.Put(3, "c")
   548  	tree.Put(1, "a")
   549  	tree.Put(2, "b")
   550  	it := tree.Iterator()
   551  	if actualValue, expectedValue := it.Last(), true; actualValue != expectedValue {
   552  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
   553  	}
   554  	if key, value := it.Key(), it.Value(); key != 3 || value != "c" {
   555  		t.Errorf("Got %v,%v expected %v,%v", key, value, 3, "c")
   556  	}
   557  }
   558  
   559  func TestAVLTreeSerialization(t *testing.T) {
   560  	tree := NewWithStringComparator()
   561  	tree.Put("c", "3")
   562  	tree.Put("b", "2")
   563  	tree.Put("a", "1")
   564  
   565  	var err error
   566  	assert := func() {
   567  		if actualValue, expectedValue := tree.Size(), 3; actualValue != expectedValue {
   568  			t.Errorf("Got %v expected %v", actualValue, expectedValue)
   569  		}
   570  		if actualValue := tree.Keys(); actualValue[0].(string) != "a" || actualValue[1].(string) != "b" || actualValue[2].(string) != "c" {
   571  			t.Errorf("Got %v expected %v", actualValue, "[a,b,c]")
   572  		}
   573  		if actualValue := tree.Values(); actualValue[0].(string) != "1" || actualValue[1].(string) != "2" || actualValue[2].(string) != "3" {
   574  			t.Errorf("Got %v expected %v", actualValue, "[1,2,3]")
   575  		}
   576  		if err != nil {
   577  			t.Errorf("Got error %v", err)
   578  		}
   579  	}
   580  
   581  	assert()
   582  
   583  	json, err := tree.ToJSON()
   584  	assert()
   585  
   586  	err = tree.FromJSON(json)
   587  	assert()
   588  }
   589  
   590  func benchmarkGet(b *testing.B, tree *Tree, size int) {
   591  	for i := 0; i < b.N; i++ {
   592  		for n := 0; n < size; n++ {
   593  			tree.Get(n)
   594  		}
   595  	}
   596  }
   597  
   598  func benchmarkPut(b *testing.B, tree *Tree, size int) {
   599  	for i := 0; i < b.N; i++ {
   600  		for n := 0; n < size; n++ {
   601  			tree.Put(n, struct{}{})
   602  		}
   603  	}
   604  }
   605  
   606  func benchmarkRemove(b *testing.B, tree *Tree, size int) {
   607  	for i := 0; i < b.N; i++ {
   608  		for n := 0; n < size; n++ {
   609  			tree.Remove(n)
   610  		}
   611  	}
   612  }
   613  
   614  func BenchmarkAVLTreeGet100(b *testing.B) {
   615  	b.StopTimer()
   616  	size := 100
   617  	tree := NewWithIntComparator()
   618  	for n := 0; n < size; n++ {
   619  		tree.Put(n, struct{}{})
   620  	}
   621  	b.StartTimer()
   622  	benchmarkGet(b, tree, size)
   623  }
   624  
   625  func BenchmarkAVLTreeGet1000(b *testing.B) {
   626  	b.StopTimer()
   627  	size := 1000
   628  	tree := NewWithIntComparator()
   629  	for n := 0; n < size; n++ {
   630  		tree.Put(n, struct{}{})
   631  	}
   632  	b.StartTimer()
   633  	benchmarkGet(b, tree, size)
   634  }
   635  
   636  func BenchmarkAVLTreeGet10000(b *testing.B) {
   637  	b.StopTimer()
   638  	size := 10000
   639  	tree := NewWithIntComparator()
   640  	for n := 0; n < size; n++ {
   641  		tree.Put(n, struct{}{})
   642  	}
   643  	b.StartTimer()
   644  	benchmarkGet(b, tree, size)
   645  }
   646  
   647  func BenchmarkAVLTreeGet100000(b *testing.B) {
   648  	b.StopTimer()
   649  	size := 100000
   650  	tree := NewWithIntComparator()
   651  	for n := 0; n < size; n++ {
   652  		tree.Put(n, struct{}{})
   653  	}
   654  	b.StartTimer()
   655  	benchmarkGet(b, tree, size)
   656  }
   657  
   658  func BenchmarkAVLTreePut100(b *testing.B) {
   659  	b.StopTimer()
   660  	size := 100
   661  	tree := NewWithIntComparator()
   662  	b.StartTimer()
   663  	benchmarkPut(b, tree, size)
   664  }
   665  
   666  func BenchmarkAVLTreePut1000(b *testing.B) {
   667  	b.StopTimer()
   668  	size := 1000
   669  	tree := NewWithIntComparator()
   670  	for n := 0; n < size; n++ {
   671  		tree.Put(n, struct{}{})
   672  	}
   673  	b.StartTimer()
   674  	benchmarkPut(b, tree, size)
   675  }
   676  
   677  func BenchmarkAVLTreePut10000(b *testing.B) {
   678  	b.StopTimer()
   679  	size := 10000
   680  	tree := NewWithIntComparator()
   681  	for n := 0; n < size; n++ {
   682  		tree.Put(n, struct{}{})
   683  	}
   684  	b.StartTimer()
   685  	benchmarkPut(b, tree, size)
   686  }
   687  
   688  func BenchmarkAVLTreePut100000(b *testing.B) {
   689  	b.StopTimer()
   690  	size := 100000
   691  	tree := NewWithIntComparator()
   692  	for n := 0; n < size; n++ {
   693  		tree.Put(n, struct{}{})
   694  	}
   695  	b.StartTimer()
   696  	benchmarkPut(b, tree, size)
   697  }
   698  
   699  func BenchmarkAVLTreeRemove100(b *testing.B) {
   700  	b.StopTimer()
   701  	size := 100
   702  	tree := NewWithIntComparator()
   703  	for n := 0; n < size; n++ {
   704  		tree.Put(n, struct{}{})
   705  	}
   706  	b.StartTimer()
   707  	benchmarkRemove(b, tree, size)
   708  }
   709  
   710  func BenchmarkAVLTreeRemove1000(b *testing.B) {
   711  	b.StopTimer()
   712  	size := 1000
   713  	tree := NewWithIntComparator()
   714  	for n := 0; n < size; n++ {
   715  		tree.Put(n, struct{}{})
   716  	}
   717  	b.StartTimer()
   718  	benchmarkRemove(b, tree, size)
   719  }
   720  
   721  func BenchmarkAVLTreeRemove10000(b *testing.B) {
   722  	b.StopTimer()
   723  	size := 10000
   724  	tree := NewWithIntComparator()
   725  	for n := 0; n < size; n++ {
   726  		tree.Put(n, struct{}{})
   727  	}
   728  	b.StartTimer()
   729  	benchmarkRemove(b, tree, size)
   730  }
   731  
   732  func BenchmarkAVLTreeRemove100000(b *testing.B) {
   733  	b.StopTimer()
   734  	size := 100000
   735  	tree := NewWithIntComparator()
   736  	for n := 0; n < size; n++ {
   737  		tree.Put(n, struct{}{})
   738  	}
   739  	b.StartTimer()
   740  	benchmarkRemove(b, tree, size)
   741  }