github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/structure/maps/linkedhashmap/linkedhashmap_test.go (about)

     1  package linkedhashmap
     2  
     3  import (
     4  	"encoding/json"
     5  	"reflect"
     6  	"strings"
     7  	"testing"
     8  )
     9  
    10  func TestMapPut(t *testing.T) {
    11  	m := New[int, string]()
    12  	m.Put(5, "e")
    13  	m.Put(6, "f")
    14  	m.Put(7, "g")
    15  	m.Put(3, "c")
    16  	m.Put(4, "d")
    17  	m.Put(1, "x")
    18  	m.Put(2, "b")
    19  	m.Put(1, "a") //overwrite
    20  
    21  	if actualValue := m.Size(); actualValue != 7 {
    22  		t.Errorf("Got %v expected %v", actualValue, 7)
    23  	}
    24  	if actualValue, expectedValue := m.Keys(), []int{5, 6, 7, 3, 4, 1, 2}; !sameElements(actualValue, expectedValue) {
    25  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
    26  	}
    27  	if actualValue, expectedValue := m.Values(), []string{"e", "f", "g", "c", "d", "a", "b"}; !sameElements(actualValue, expectedValue) {
    28  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
    29  	}
    30  
    31  	// key,expectedValue,expectedFound
    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, "", false},
    41  	}
    42  
    43  	for _, test := range tests1 {
    44  		// retrievals
    45  		actualValue, actualFound := m.Get(test[0].(int))
    46  		if actualValue != test[1] || actualFound != test[2] {
    47  			t.Errorf("Got %v expected %v", actualValue, test[1])
    48  		}
    49  	}
    50  }
    51  
    52  func TestMapRemove(t *testing.T) {
    53  	m := New[int, string]()
    54  	m.Put(5, "e")
    55  	m.Put(6, "f")
    56  	m.Put(7, "g")
    57  	m.Put(3, "c")
    58  	m.Put(4, "d")
    59  	m.Put(1, "x")
    60  	m.Put(2, "b")
    61  	m.Put(1, "a") //overwrite
    62  
    63  	m.Remove(5)
    64  	m.Remove(6)
    65  	m.Remove(7)
    66  	m.Remove(8)
    67  	m.Remove(5)
    68  
    69  	if actualValue, expectedValue := m.Keys(), []int{3, 4, 1, 2}; !sameElements(actualValue, expectedValue) {
    70  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
    71  	}
    72  
    73  	if actualValue, expectedValue := m.Values(), []string{"c", "d", "a", "b"}; !sameElements(actualValue, expectedValue) {
    74  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
    75  	}
    76  	if actualValue := m.Size(); actualValue != 4 {
    77  		t.Errorf("Got %v expected %v", actualValue, 4)
    78  	}
    79  
    80  	tests2 := [][]interface{}{
    81  		{1, "a", true},
    82  		{2, "b", true},
    83  		{3, "c", true},
    84  		{4, "d", true},
    85  		{5, "", false},
    86  		{6, "", false},
    87  		{7, "", false},
    88  		{8, "", false},
    89  	}
    90  
    91  	for _, test := range tests2 {
    92  		actualValue, actualFound := m.Get(test[0].(int))
    93  		if actualValue != test[1] || actualFound != test[2] {
    94  			t.Errorf("Got %v expected %v", actualValue, test[1])
    95  		}
    96  	}
    97  
    98  	m.Remove(1)
    99  	m.Remove(4)
   100  	m.Remove(2)
   101  	m.Remove(3)
   102  	m.Remove(2)
   103  	m.Remove(2)
   104  
   105  	if actualValue, expectedValue := m.Keys(), []int{}; !reflect.DeepEqual(actualValue, expectedValue) {
   106  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
   107  	}
   108  	if actualValue, expectedValue := m.Values(), []string{}; !reflect.DeepEqual(actualValue, expectedValue) {
   109  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
   110  	}
   111  	if actualValue := m.Size(); actualValue != 0 {
   112  		t.Errorf("Got %v expected %v", actualValue, 0)
   113  	}
   114  	if actualValue := m.Empty(); actualValue != true {
   115  		t.Errorf("Got %v expected %v", actualValue, true)
   116  	}
   117  }
   118  
   119  func sameElements[E any](a []E, b []E) bool {
   120  	// If one is nil, the other must also be nil.
   121  	if (a == nil) != (b == nil) {
   122  		return false
   123  	}
   124  
   125  	if len(a) != len(b) {
   126  		return false
   127  	}
   128  
   129  	for i := range a {
   130  		if !reflect.DeepEqual(a[i], b[i]) {
   131  			return false
   132  		}
   133  	}
   134  
   135  	return true
   136  }
   137  
   138  func TestMapEach(t *testing.T) {
   139  	m := New[string, int]()
   140  	m.Put("c", 1)
   141  	m.Put("a", 2)
   142  	m.Put("b", 3)
   143  	count := 0
   144  	m.Each(func(key string, value int) {
   145  		count++
   146  		if actualValue, expectedValue := count, value; actualValue != expectedValue {
   147  			t.Errorf("Got %v expected %v", actualValue, expectedValue)
   148  		}
   149  		switch value {
   150  		case 1:
   151  			if actualValue, expectedValue := key, "c"; actualValue != expectedValue {
   152  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   153  			}
   154  		case 2:
   155  			if actualValue, expectedValue := key, "a"; actualValue != expectedValue {
   156  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   157  			}
   158  		case 3:
   159  			if actualValue, expectedValue := key, "b"; actualValue != expectedValue {
   160  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   161  			}
   162  		default:
   163  			t.Errorf("Too many")
   164  		}
   165  	})
   166  }
   167  
   168  func TestMapMap(t *testing.T) {
   169  	m := New[string, int]()
   170  	m.Put("c", 3)
   171  	m.Put("a", 1)
   172  	m.Put("b", 2)
   173  	mappedMap := m.Map(func(key1 string, value1 int) (key2 string, value2 int) {
   174  		return key1, value1 * value1
   175  	})
   176  	if actualValue, _ := mappedMap.Get("c"); actualValue != 9 {
   177  		t.Errorf("Got %v expected %v", actualValue, "mapped: c")
   178  	}
   179  	if actualValue, _ := mappedMap.Get("a"); actualValue != 1 {
   180  		t.Errorf("Got %v expected %v", actualValue, "mapped: a")
   181  	}
   182  	if actualValue, _ := mappedMap.Get("b"); actualValue != 4 {
   183  		t.Errorf("Got %v expected %v", actualValue, "mapped: b")
   184  	}
   185  	if mappedMap.Size() != 3 {
   186  		t.Errorf("Got %v expected %v", mappedMap.Size(), 3)
   187  	}
   188  }
   189  
   190  func TestMapSelect(t *testing.T) {
   191  	m := New[string, int]()
   192  	m.Put("c", 3)
   193  	m.Put("b", 1)
   194  	m.Put("a", 2)
   195  	selectedMap := m.Select(func(key string, value int) bool {
   196  		return key >= "a" && key <= "b"
   197  	})
   198  	if actualValue, _ := selectedMap.Get("b"); actualValue != 1 {
   199  		t.Errorf("Got %v expected %v", actualValue, "value: a")
   200  	}
   201  	if actualValue, _ := selectedMap.Get("a"); actualValue != 2 {
   202  		t.Errorf("Got %v expected %v", actualValue, "value: b")
   203  	}
   204  	if selectedMap.Size() != 2 {
   205  		t.Errorf("Got %v expected %v", selectedMap.Size(), 2)
   206  	}
   207  }
   208  
   209  func TestMapAny(t *testing.T) {
   210  	m := New[string, int]()
   211  	m.Put("c", 3)
   212  	m.Put("a", 1)
   213  	m.Put("b", 2)
   214  	any := m.Any(func(key string, value int) bool {
   215  		return value == 3
   216  	})
   217  	if any != true {
   218  		t.Errorf("Got %v expected %v", any, true)
   219  	}
   220  	any = m.Any(func(key string, value int) bool {
   221  		return value == 4
   222  	})
   223  	if any != false {
   224  		t.Errorf("Got %v expected %v", any, false)
   225  	}
   226  }
   227  
   228  func TestMapAll(t *testing.T) {
   229  	m := New[string, int]()
   230  	m.Put("c", 3)
   231  	m.Put("a", 1)
   232  	m.Put("b", 2)
   233  	all := m.All(func(key string, value int) bool {
   234  		return key >= "a" && key <= "c"
   235  	})
   236  	if all != true {
   237  		t.Errorf("Got %v expected %v", all, true)
   238  	}
   239  	all = m.All(func(key string, value int) bool {
   240  		return key >= "a" && key <= "b"
   241  	})
   242  	if all != false {
   243  		t.Errorf("Got %v expected %v", all, false)
   244  	}
   245  }
   246  
   247  func TestMapFind(t *testing.T) {
   248  	m := New[string, int]()
   249  	m.Put("c", 3)
   250  	m.Put("a", 1)
   251  	m.Put("b", 2)
   252  	foundKey, foundValue := m.Find(func(key string, value int) bool {
   253  		return key == "c"
   254  	})
   255  	if foundKey != "c" || foundValue != 3 {
   256  		t.Errorf("Got %v -> %v expected %v -> %v", foundKey, foundValue, "c", 3)
   257  	}
   258  	foundKey, foundValue = m.Find(func(key string, value int) bool {
   259  		return key == "x"
   260  	})
   261  	if foundKey != "" || foundValue != 0 {
   262  		t.Errorf("Got %v at %v expected %v at %v", foundValue, foundKey, nil, nil)
   263  	}
   264  }
   265  
   266  func TestMapChaining(t *testing.T) {
   267  	m := New[string, int]()
   268  	m.Put("c", 3)
   269  	m.Put("a", 1)
   270  	m.Put("b", 2)
   271  	chainedMap := m.Select(func(key string, value int) bool {
   272  		return value > 1
   273  	}).Map(func(key string, value int) (string, int) {
   274  		return key + key, value * value
   275  	})
   276  	if actualValue := chainedMap.Size(); actualValue != 2 {
   277  		t.Errorf("Got %v expected %v", actualValue, 2)
   278  	}
   279  	if actualValue, found := chainedMap.Get("aa"); actualValue != 0 || found {
   280  		t.Errorf("Got %v expected %v", actualValue, nil)
   281  	}
   282  	if actualValue, found := chainedMap.Get("bb"); actualValue != 4 || !found {
   283  		t.Errorf("Got %v expected %v", actualValue, 4)
   284  	}
   285  	if actualValue, found := chainedMap.Get("cc"); actualValue != 9 || !found {
   286  		t.Errorf("Got %v expected %v", actualValue, 9)
   287  	}
   288  }
   289  
   290  func TestMapIteratorNextOnEmpty(t *testing.T) {
   291  	m := New[string, struct{}]()
   292  	it := m.Iterator()
   293  	it = m.Iterator()
   294  	for it.Next() {
   295  		t.Errorf("Shouldn't iterate on empty map")
   296  	}
   297  }
   298  
   299  func TestMapIteratorPrevOnEmpty(t *testing.T) {
   300  	m := New[string, struct{}]()
   301  	it := m.Iterator()
   302  	it = m.Iterator()
   303  	for it.Prev() {
   304  		t.Errorf("Shouldn't iterate on empty map")
   305  	}
   306  }
   307  
   308  func TestMapIteratorNext(t *testing.T) {
   309  	m := New[string, int]()
   310  	m.Put("c", 1)
   311  	m.Put("a", 2)
   312  	m.Put("b", 3)
   313  
   314  	it := m.Iterator()
   315  	count := 0
   316  	for it.Next() {
   317  		count++
   318  		key := it.Key()
   319  		value := it.Value()
   320  		switch key {
   321  		case "c":
   322  			if actualValue, expectedValue := value, 1; actualValue != expectedValue {
   323  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   324  			}
   325  		case "a":
   326  			if actualValue, expectedValue := value, 2; actualValue != expectedValue {
   327  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   328  			}
   329  		case "b":
   330  			if actualValue, expectedValue := value, 3; actualValue != expectedValue {
   331  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   332  			}
   333  		default:
   334  			t.Errorf("Too many")
   335  		}
   336  		if actualValue, expectedValue := value, count; actualValue != expectedValue {
   337  			t.Errorf("Got %v expected %v", actualValue, expectedValue)
   338  		}
   339  	}
   340  	if actualValue, expectedValue := count, 3; actualValue != expectedValue {
   341  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
   342  	}
   343  }
   344  
   345  func TestMapIteratorPrev(t *testing.T) {
   346  	m := New[string, int]()
   347  	m.Put("c", 1)
   348  	m.Put("a", 2)
   349  	m.Put("b", 3)
   350  
   351  	it := m.Iterator()
   352  	for it.Next() {
   353  	}
   354  	countDown := m.Size()
   355  	for it.Prev() {
   356  		key := it.Key()
   357  		value := it.Value()
   358  		switch key {
   359  		case "c":
   360  			if actualValue, expectedValue := value, 1; actualValue != expectedValue {
   361  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   362  			}
   363  		case "a":
   364  			if actualValue, expectedValue := value, 2; actualValue != expectedValue {
   365  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   366  			}
   367  		case "b":
   368  			if actualValue, expectedValue := value, 3; actualValue != expectedValue {
   369  				t.Errorf("Got %v expected %v", actualValue, expectedValue)
   370  			}
   371  		default:
   372  			t.Errorf("Too many")
   373  		}
   374  		if actualValue, expectedValue := value, countDown; actualValue != expectedValue {
   375  			t.Errorf("Got %v expected %v", actualValue, expectedValue)
   376  		}
   377  		countDown--
   378  	}
   379  	if actualValue, expectedValue := countDown, 0; actualValue != expectedValue {
   380  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
   381  	}
   382  }
   383  
   384  func TestMapIteratorBegin(t *testing.T) {
   385  	m := New[int, string]()
   386  	it := m.Iterator()
   387  	it.Begin()
   388  	m.Put(3, "c")
   389  	m.Put(1, "a")
   390  	m.Put(2, "b")
   391  	for it.Next() {
   392  	}
   393  	it.Begin()
   394  	it.Next()
   395  	if key, value := it.Key(), it.Value(); key != 3 || value != "c" {
   396  		t.Errorf("Got %v,%v expected %v,%v", key, value, 3, "c")
   397  	}
   398  }
   399  
   400  func TestMapIteratorEnd(t *testing.T) {
   401  	m := New[int, string]()
   402  	it := m.Iterator()
   403  	m.Put(3, "c")
   404  	m.Put(1, "a")
   405  	m.Put(2, "b")
   406  	it.End()
   407  	it.Prev()
   408  	if key, value := it.Key(), it.Value(); key != 2 || value != "b" {
   409  		t.Errorf("Got %v,%v expected %v,%v", key, value, 2, "b")
   410  	}
   411  }
   412  
   413  func TestMapIteratorFirst(t *testing.T) {
   414  	m := New[int, string]()
   415  	m.Put(3, "c")
   416  	m.Put(1, "a")
   417  	m.Put(2, "b")
   418  	it := m.Iterator()
   419  	if actualValue, expectedValue := it.First(), true; actualValue != expectedValue {
   420  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
   421  	}
   422  	if key, value := it.Key(), it.Value(); key != 3 || value != "c" {
   423  		t.Errorf("Got %v,%v expected %v,%v", key, value, 3, "c")
   424  	}
   425  }
   426  
   427  func TestMapIteratorLast(t *testing.T) {
   428  	m := New[int, string]()
   429  	m.Put(3, "c")
   430  	m.Put(1, "a")
   431  	m.Put(2, "b")
   432  	it := m.Iterator()
   433  	if actualValue, expectedValue := it.Last(), true; actualValue != expectedValue {
   434  		t.Errorf("Got %v expected %v", actualValue, expectedValue)
   435  	}
   436  	if key, value := it.Key(), it.Value(); key != 2 || value != "b" {
   437  		t.Errorf("Got %v,%v expected %v,%v", key, value, 2, "b")
   438  	}
   439  }
   440  
   441  func TestMapIteratorNextTo(t *testing.T) {
   442  	// Sample seek function, i.e. string starting with "b"
   443  	seek := func(index int, value string) bool {
   444  		return strings.HasSuffix(value, "b")
   445  	}
   446  
   447  	// NextTo (empty)
   448  	{
   449  		m := New[int, string]()
   450  		it := m.Iterator()
   451  		for it.NextTo(seek) {
   452  			t.Errorf("Shouldn't iterate on empty map")
   453  		}
   454  	}
   455  
   456  	// NextTo (not found)
   457  	{
   458  		m := New[int, string]()
   459  		m.Put(0, "xx")
   460  		m.Put(1, "yy")
   461  		it := m.Iterator()
   462  		for it.NextTo(seek) {
   463  			t.Errorf("Shouldn't iterate on empty map")
   464  		}
   465  	}
   466  
   467  	// NextTo (found)
   468  	{
   469  		m := New[int, string]()
   470  		m.Put(0, "aa")
   471  		m.Put(1, "bb")
   472  		m.Put(2, "cc")
   473  		it := m.Iterator()
   474  		it.Begin()
   475  		if !it.NextTo(seek) {
   476  			t.Errorf("Shouldn't iterate on empty map")
   477  		}
   478  		if index, value := it.Key(), it.Value(); index != 1 || value != "bb" {
   479  			t.Errorf("Got %v,%v expected %v,%v", index, value, 1, "bb")
   480  		}
   481  		if !it.Next() {
   482  			t.Errorf("Should go to first element")
   483  		}
   484  		if index, value := it.Key(), it.Value(); index != 2 || value != "cc" {
   485  			t.Errorf("Got %v,%v expected %v,%v", index, value, 2, "cc")
   486  		}
   487  		if it.Next() {
   488  			t.Errorf("Should not go past last element")
   489  		}
   490  	}
   491  }
   492  
   493  func TestMapIteratorPrevTo(t *testing.T) {
   494  	// Sample seek function, i.e. string starting with "b"
   495  	seek := func(index int, value string) bool {
   496  		return strings.HasSuffix(value, "b")
   497  	}
   498  
   499  	// PrevTo (empty)
   500  	{
   501  		m := New[int, string]()
   502  		it := m.Iterator()
   503  		it.End()
   504  		for it.PrevTo(seek) {
   505  			t.Errorf("Shouldn't iterate on empty map")
   506  		}
   507  	}
   508  
   509  	// PrevTo (not found)
   510  	{
   511  		m := New[int, string]()
   512  		m.Put(0, "xx")
   513  		m.Put(1, "yy")
   514  		it := m.Iterator()
   515  		it.End()
   516  		for it.PrevTo(seek) {
   517  			t.Errorf("Shouldn't iterate on empty map")
   518  		}
   519  	}
   520  
   521  	// PrevTo (found)
   522  	{
   523  		m := New[int, string]()
   524  		m.Put(0, "aa")
   525  		m.Put(1, "bb")
   526  		m.Put(2, "cc")
   527  		it := m.Iterator()
   528  		it.End()
   529  		if !it.PrevTo(seek) {
   530  			t.Errorf("Shouldn't iterate on empty map")
   531  		}
   532  		if index, value := it.Key(), it.Value(); index != 1 || value != "bb" {
   533  			t.Errorf("Got %v,%v expected %v,%v", index, value, 1, "bb")
   534  		}
   535  		if !it.Prev() {
   536  			t.Errorf("Should go to first element")
   537  		}
   538  		if index, value := it.Key(), it.Value(); index != 0 || value != "aa" {
   539  			t.Errorf("Got %v,%v expected %v,%v", index, value, 0, "aa")
   540  		}
   541  		if it.Prev() {
   542  			t.Errorf("Should not go before first element")
   543  		}
   544  	}
   545  }
   546  
   547  func TestMapSerialization(t *testing.T) {
   548  	for i := 0; i < 10; i++ {
   549  		original := New[string, string]()
   550  		original.Put("d", "4")
   551  		original.Put("e", "5")
   552  		original.Put("c", "3")
   553  		original.Put("b", "2")
   554  		original.Put("a", "1")
   555  
   556  		assertSerialization(original, "A", t)
   557  
   558  		serialized, err := original.MarshalJSON()
   559  		if err != nil {
   560  			t.Errorf("Got error %v", err)
   561  		}
   562  		assertSerialization(original, "B", t)
   563  
   564  		deserialized := New[string, string]()
   565  		err = deserialized.UnmarshalJSON(serialized)
   566  		if err != nil {
   567  			t.Errorf("Got error %v", err)
   568  		}
   569  		assertSerialization(deserialized, "C", t)
   570  	}
   571  
   572  	m := New[string, float64]()
   573  	m.Put("a", 1.0)
   574  	m.Put("b", 2.0)
   575  	m.Put("c", 3.0)
   576  
   577  	_, err := json.Marshal([]interface{}{"a", "b", "c", m})
   578  	if err != nil {
   579  		t.Errorf("Got error %v", err)
   580  	}
   581  
   582  	err = json.Unmarshal([]byte(`{"a":1,"b":2}`), &m)
   583  	if err != nil {
   584  		t.Errorf("Got error %v", err)
   585  	}
   586  }
   587  
   588  func TestMapString(t *testing.T) {
   589  	c := New[string, int]()
   590  	c.Put("a", 1)
   591  	if !strings.HasPrefix(c.String(), "LinkedHashMap") {
   592  		t.Errorf("String should start with container name")
   593  	}
   594  }
   595  
   596  // noinspection GoBoolExpressions
   597  func assertSerialization(m *Map[string, string], txt string, t *testing.T) {
   598  	if actualValue := m.Keys(); false ||
   599  		actualValue[0] != "d" ||
   600  		actualValue[1] != "e" ||
   601  		actualValue[2] != "c" ||
   602  		actualValue[3] != "b" ||
   603  		actualValue[4] != "a" {
   604  		t.Errorf("[%s] Got %v expected %v", txt, actualValue, "[d,e,c,b,a]")
   605  	}
   606  	if actualValue := m.Values(); false ||
   607  		actualValue[0] != "4" ||
   608  		actualValue[1] != "5" ||
   609  		actualValue[2] != "3" ||
   610  		actualValue[3] != "2" ||
   611  		actualValue[4] != "1" {
   612  		t.Errorf("[%s] Got %v expected %v", txt, actualValue, "[4,5,3,2,1]")
   613  	}
   614  	if actualValue, expectedValue := m.Size(), 5; actualValue != expectedValue {
   615  		t.Errorf("[%s] Got %v expected %v", txt, actualValue, expectedValue)
   616  	}
   617  }
   618  
   619  func benchmarkGet[K int, V struct{}](b *testing.B, m *Map[K, V], size int) {
   620  	for i := 0; i < b.N; i++ {
   621  		for n := 0; n < size; n++ {
   622  			m.Get(K(n))
   623  		}
   624  	}
   625  }
   626  
   627  func benchmarkPut[K int, V struct{}](b *testing.B, m *Map[K, V], size int) {
   628  	for i := 0; i < b.N; i++ {
   629  		for n := 0; n < size; n++ {
   630  			m.Put(K(n), struct{}{})
   631  		}
   632  	}
   633  }
   634  
   635  func benchmarkRemove[K int, V struct{}](b *testing.B, m *Map[K, V], size int) {
   636  	for i := 0; i < b.N; i++ {
   637  		for n := 0; n < size; n++ {
   638  			m.Remove(K(n))
   639  		}
   640  	}
   641  }
   642  
   643  func BenchmarkTreeMapGet100(b *testing.B) {
   644  	b.StopTimer()
   645  	size := 100
   646  	m := New[int, struct{}]()
   647  	for n := 0; n < size; n++ {
   648  		m.Put(n, struct{}{})
   649  	}
   650  	b.StartTimer()
   651  	benchmarkGet(b, m, size)
   652  }
   653  
   654  func BenchmarkTreeMapGet1000(b *testing.B) {
   655  	b.StopTimer()
   656  	size := 1000
   657  	m := New[int, struct{}]()
   658  	for n := 0; n < size; n++ {
   659  		m.Put(n, struct{}{})
   660  	}
   661  	b.StartTimer()
   662  	benchmarkGet(b, m, size)
   663  }
   664  
   665  func BenchmarkTreeMapGet10000(b *testing.B) {
   666  	b.StopTimer()
   667  	size := 10000
   668  	m := New[int, struct{}]()
   669  	for n := 0; n < size; n++ {
   670  		m.Put(n, struct{}{})
   671  	}
   672  	b.StartTimer()
   673  	benchmarkGet(b, m, size)
   674  }
   675  
   676  func BenchmarkTreeMapGet100000(b *testing.B) {
   677  	b.StopTimer()
   678  	size := 100000
   679  	m := New[int, struct{}]()
   680  	for n := 0; n < size; n++ {
   681  		m.Put(n, struct{}{})
   682  	}
   683  	b.StartTimer()
   684  	benchmarkGet(b, m, size)
   685  }
   686  
   687  func BenchmarkTreeMapPut100(b *testing.B) {
   688  	b.StopTimer()
   689  	size := 100
   690  	m := New[int, struct{}]()
   691  	b.StartTimer()
   692  	benchmarkPut(b, m, size)
   693  }
   694  
   695  func BenchmarkTreeMapPut1000(b *testing.B) {
   696  	b.StopTimer()
   697  	size := 1000
   698  	m := New[int, struct{}]()
   699  	for n := 0; n < size; n++ {
   700  		m.Put(n, struct{}{})
   701  	}
   702  	b.StartTimer()
   703  	benchmarkPut(b, m, size)
   704  }
   705  
   706  func BenchmarkTreeMapPut10000(b *testing.B) {
   707  	b.StopTimer()
   708  	size := 10000
   709  	m := New[int, struct{}]()
   710  	for n := 0; n < size; n++ {
   711  		m.Put(n, struct{}{})
   712  	}
   713  	b.StartTimer()
   714  	benchmarkPut(b, m, size)
   715  }
   716  
   717  func BenchmarkTreeMapPut100000(b *testing.B) {
   718  	b.StopTimer()
   719  	size := 100000
   720  	m := New[int, struct{}]()
   721  	for n := 0; n < size; n++ {
   722  		m.Put(n, struct{}{})
   723  	}
   724  	b.StartTimer()
   725  	benchmarkPut(b, m, size)
   726  }
   727  
   728  func BenchmarkTreeMapRemove100(b *testing.B) {
   729  	b.StopTimer()
   730  	size := 100
   731  	m := New[int, struct{}]()
   732  	for n := 0; n < size; n++ {
   733  		m.Put(n, struct{}{})
   734  	}
   735  	b.StartTimer()
   736  	benchmarkRemove(b, m, size)
   737  }
   738  
   739  func BenchmarkTreeMapRemove1000(b *testing.B) {
   740  	b.StopTimer()
   741  	size := 1000
   742  	m := New[int, struct{}]()
   743  	for n := 0; n < size; n++ {
   744  		m.Put(n, struct{}{})
   745  	}
   746  	b.StartTimer()
   747  	benchmarkRemove(b, m, size)
   748  }
   749  
   750  func BenchmarkTreeMapRemove10000(b *testing.B) {
   751  	b.StopTimer()
   752  	size := 10000
   753  	m := New[int, struct{}]()
   754  	for n := 0; n < size; n++ {
   755  		m.Put(n, struct{}{})
   756  	}
   757  	b.StartTimer()
   758  	benchmarkRemove(b, m, size)
   759  }
   760  
   761  func BenchmarkTreeMapRemove100000(b *testing.B) {
   762  	b.StopTimer()
   763  	size := 100000
   764  	m := New[int, struct{}]()
   765  	for n := 0; n < size; n++ {
   766  		m.Put(n, struct{}{})
   767  	}
   768  	b.StartTimer()
   769  	benchmarkRemove(b, m, size)
   770  }