@@ -109,6 +109,40 @@ describe(`Deterministic Ordering`, () => {
109109 } )
110110
111111 describe ( `BTreeIndex` , ( ) => {
112+ it ( `should handle undefined indexed values with take and limit` , ( ) => {
113+ const index = new BTreeIndex < string > (
114+ 1 ,
115+ new PropRef ( [ `priority` ] ) ,
116+ `priority_index` ,
117+ )
118+
119+ // Add items where priority is undefined
120+ index . add ( `a` , { priority : undefined } )
121+ index . add ( `b` , { priority : undefined } )
122+ index . add ( `c` , { priority : 1 } )
123+
124+ // take() with a limit should return results without hanging
125+ const keys = index . take ( 2 )
126+ expect ( keys ) . toEqual ( [ `a` , `b` ] )
127+ } )
128+
129+ it ( `should handle undefined indexed values with takeReversed and limit` , ( ) => {
130+ const index = new BTreeIndex < string > (
131+ 1 ,
132+ new PropRef ( [ `priority` ] ) ,
133+ `priority_index` ,
134+ )
135+
136+ // Add items where priority is undefined
137+ index . add ( `a` , { priority : undefined } )
138+ index . add ( `b` , { priority : undefined } )
139+ index . add ( `c` , { priority : 1 } )
140+
141+ // takeReversed() with a limit should return results without hanging
142+ const keys = index . takeReversed ( 2 )
143+ expect ( keys ) . toEqual ( [ `c` , `b` ] )
144+ } )
145+
112146 it ( `should return keys in deterministic order when indexed values are equal` , ( ) => {
113147 const index = new BTreeIndex < string > (
114148 1 ,
0 commit comments