@@ -36,7 +36,7 @@ enableOrderStatistic?: boolean; // default: false
3636
3737When ` false ` (default):
3838- ` _count ` is NOT maintained (no overhead)
39- - ` select ()` , ` rank ()` , ` rangeByRank() ` throw ` Error('Order statistic is not enabled') `
39+ - ` getByRank ()` , ` getRank ()` , ` rangeByRank() ` throw ` Error('Order statistic is not enabled') `
4040
4141When ` true ` :
4242- ` _count ` is maintained on every insert, delete, and rotation
@@ -47,7 +47,7 @@ When `true`:
4747The option propagates through the inheritance chain:
4848``` ts
4949const map = new TreeMap <string , number >([], { enableOrderStatistic: true });
50- map .select (0 ); // ✅ works
50+ map .getByRank (0 ); // ✅ works
5151```
5252
5353## API Design
@@ -93,29 +93,29 @@ const tree = new RedBlackTree<number>(
9393 { enableOrderStatistic: true }
9494);
9595
96- tree .select (0 ); // 20 (smallest)
97- tree .select (3 ); // 50 (median)
98- tree .select (6 ); // 80 (largest)
99- tree .select (7 ); // undefined (out of bounds)
100- tree .select (- 1 ); // undefined
96+ tree .getByRank (0 ); // 20 (smallest)
97+ tree .getByRank (3 ); // 50 (median)
98+ tree .getByRank (6 ); // 80 (largest)
99+ tree .getByRank (7 ); // undefined (out of bounds)
100+ tree .getByRank (- 1 ); // undefined
101101
102102// With callback — get node
103- tree .select (3 , node => node ); // BSTNode { key: 50 }
103+ tree .getByRank (3 , node => node ); // BSTNode { key: 50 }
104104
105105// With callback — get entry
106- tree .select (3 , node => [node .key , node .value ]); // [50, undefined]
106+ tree .getByRank (3 , node => [node .key , node .value ]); // [50, undefined]
107107
108108// TreeMap
109109const map = new TreeMap <string , number >(
110110 [[' alice' , 95 ], [' bob' , 87 ], [' charlie' , 92 ]],
111111 { enableOrderStatistic: true }
112112);
113- map .select (0 ); // 'alice' (keys sorted alphabetically)
114- map .select (2 ); // 'charlie'
113+ map .getByRank (0 ); // 'alice' (keys sorted alphabetically)
114+ map .getByRank (2 ); // 'charlie'
115115
116116// TreeSet
117117const set = new TreeSet <number >([10 , 20 , 30 ], { enableOrderStatistic: true });
118- set .select (1 ); // 20
118+ set .getByRank (1 ); // 20
119119```
120120
121121### rank(key) — Get the rank of a key
@@ -172,23 +172,23 @@ const tree = new RedBlackTree<number>(
172172 { enableOrderStatistic: true }
173173);
174174
175- tree .rank (10 ); // 0 (smallest, 0 elements less than it)
176- tree .rank (30 ); // 2 (20 and 10 are less)
177- tree .rank (50 ); // 4
178- tree .rank (25 ); // 2 (would be inserted at position 2)
179- tree .rank (5 ); // 0 (would be inserted at position 0)
180- tree .rank (100 ); // 5 (would be inserted at end)
175+ tree .getRank (10 ); // 0 (smallest, 0 elements less than it)
176+ tree .getRank (30 ); // 2 (20 and 10 are less)
177+ tree .getRank (50 ); // 4
178+ tree .getRank (25 ); // 2 (would be inserted at position 2)
179+ tree .getRank (5 ); // 0 (would be inserted at position 0)
180+ tree .getRank (100 ); // 5 (would be inserted at end)
181181
182182// Inverse relationship
183- tree .select (tree .rank (30 )); // 30
184- tree .rank (tree .select (2 )! ); // 2
183+ tree .getByRank (tree .getRank (30 )); // 30
184+ tree .getRank (tree .getByRank (2 )! ); // 2
185185
186186// TreeMap
187187const map = new TreeMap <string , number >(
188188 [[' alice' , 95 ], [' bob' , 87 ], [' charlie' , 92 ]],
189189 { enableOrderStatistic: true }
190190);
191- map .rank (' bob' ); // 1
191+ map .getRank (' bob' ); // 1
192192```
193193
194194### rangeByRank(start, end) — Get elements by rank range
@@ -312,8 +312,8 @@ rangeByRank(start: number, end: number): (K | undefined)[] {
312312```
313313
314314Each call site provides a sensible fallback value after ` raise() ` :
315- - ` select ` → ` undefined `
316- - ` rank ` → ` -1 `
315+ - ` getByRank ` → ` undefined `
316+ - ` getRank ` → ` -1 `
317317- ` rangeByRank ` → ` [] `
318318
319319In ` throw ` mode (default), the fallback is never reached. In other modes, the function degrades gracefully.
@@ -324,12 +324,12 @@ New code uses `raise()`. Existing `throw` statements are gradually migrated —
324324
325325## IterationType Support
326326
327- Both ` select ` and ` rank ` walk a single root-to-leaf path, similar to ` ceiling ` /` floor ` .
327+ Both ` getByRank ` and ` getRank ` walk a single root-to-leaf path, similar to ` ceiling ` /` floor ` .
328328
329329- ** ITERATIVE** (default): while loop, O(1) space
330330- ** RECURSIVE** : function calls, O(log n) stack space
331331
332- ` rangeByRank ` uses ` select ` + in-order traversal, both support IterationType.
332+ ` rangeByRank ` uses ` getByRank ` + in-order traversal, both support IterationType.
333333
334334## Edge Cases
335335
@@ -374,7 +374,7 @@ In TreeMultiMap, a single node can represent multiple entries.
374374 - With callback
375375
3763764 . ** Inverse relationship**
377- - ` select(rank (key)) === key` for all keys
377+ - ` getByRank(getRank (key)) === key` for all keys
378378 - ` rank(select(k)) === k ` for all valid k
379379
3803805 . ** Count maintenance**
@@ -390,14 +390,14 @@ In TreeMultiMap, a single node can represent multiple entries.
390390 - TreeMultiSet: duplicate handling
391391
3923927 . ** enableOrderStatistic: false**
393- - select/rank /rangeByRank all throw
393+ - getByRank/getRank /rangeByRank all throw
394394 - No count maintenance overhead (count stays 1)
395395
3963968 . ** IterationType**
397397 - All methods produce same results with RECURSIVE and ITERATIVE
398398
3993999 . ** Stress test**
400- - Insert 10K random elements, verify select/rank consistency
400+ - Insert 10K random elements, verify getByRank/getRank consistency
401401 - Random insert/delete sequence, verify count integrity after each operation
402402
403403## Implementation Order
@@ -408,8 +408,8 @@ In TreeMultiMap, a single node can represent multiple entries.
4084084 . Wire count updates into BST insert/delete
4094095 . Wire count updates into AVL rotations
4104106 . Wire count updates into RBT rotations + fixup
411- 7 . Implement ` select `
412- 8 . Implement ` rank `
411+ 7 . Implement ` getByRank `
412+ 8 . Implement ` getRank `
4134139 . Implement ` rangeByRank `
41441410 . Verify all tests pass
41541511 . Run performance benchmark (before/after with enableOrderStatistic: false)
0 commit comments