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