@@ -294,11 +294,11 @@ impl QuickList {
294294 }
295295
296296 let max_bytes = kb * 1024 ;
297+ let merge_threshold = max_bytes / 4 ;
297298
298299 let should_merge = {
299300 let node = & self . nodes [ index] ;
300301 let next = & self . nodes [ index + 1 ] ;
301- let merge_threshold = max_bytes / 4 ;
302302
303303 ( node. entry_count > 0 && next. entry_count > 0 )
304304 && ( node. byte_size ( ) < merge_threshold || next. byte_size ( ) < merge_threshold)
@@ -408,10 +408,13 @@ impl QuickList {
408408 pub fn compress ( & mut self ) {
409409 let node_count = self . nodes . len ( ) ;
410410 if self . compress_depth > 0 && node_count > self . compress_depth * 2 {
411- for i in self . compress_depth ..( node_count - self . compress_depth ) {
412- if let Some ( node) = self . nodes . get_mut ( i) {
413- node. try_compress ( ) ;
414- }
411+ for node in self
412+ . nodes
413+ . iter_mut ( )
414+ . skip ( self . compress_depth )
415+ . take ( node_count - self . compress_depth * 2 )
416+ {
417+ node. try_compress ( ) ;
415418 }
416419 }
417420 }
@@ -502,6 +505,32 @@ impl QuickList {
502505 self . rpush ( element) ;
503506 }
504507 }
508+
509+ pub ( crate ) fn lindex ( & mut self , index : isize ) -> Option < Bytes > {
510+ if self . len == 0 {
511+ return None ;
512+ }
513+
514+ // Calculate absolute index
515+ let len = self . len as isize ;
516+ let index = if index < 0 { ( len + index) . max ( 0 ) } else { index } as usize ;
517+
518+ if index >= self . len {
519+ return None ; // Out of bounds
520+ }
521+
522+ let mut current_index = 0 ;
523+ for node in & mut self . nodes {
524+ if current_index + node. entry_count > index {
525+ node. ensure_decompressed ( & self . fill_factor ) ;
526+ if let NodeData :: Uncompressed ( ziplist) = & node. data {
527+ return ziplist. to_vec ( ) . get ( index - current_index) . cloned ( ) ;
528+ }
529+ }
530+ current_index += node. entry_count ;
531+ }
532+ None
533+ }
505534}
506535
507536#[ cfg( test) ]
0 commit comments