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