@@ -2321,7 +2321,9 @@ pub mod tuple {
23212321 column. push ( ( i, i as u8 , i. to_string ( ) ) ) ;
23222322 column. push ( ( i, i as u8 , "" . to_string ( ) ) ) ;
23232323 }
2324- assert_eq ! ( column. heap_size( ) , ( 8190 , 11040 ) ) ;
2324+ // NB: Rust seems to change the capacities across versions (1.88 != 1.89),
2325+ // so we just compare the allocated regions to avoid updating the MSRV.
2326+ assert_eq ! ( column. heap_size( ) . 0 , 8190 ) ;
23252327
23262328 }
23272329 }
@@ -3075,182 +3077,6 @@ pub mod lookback {
30753077 }
30763078}
30773079
3078- /// Containers for `Vec<(K, V)>` that form columns by `K` keys.
3079- mod maps {
3080-
3081- use crate :: { Len , Push } ;
3082- use crate :: Options ;
3083-
3084- /// A container for `Vec<(K, V)>` items.
3085- ///
3086- /// Each inserted map is expected to have one `val` for any `key`.
3087- /// Each is stored with `None` variants for absent keys. As such,
3088- /// this type is not meant for large sparse key spaces.
3089- pub struct KeyMaps < CK , CV > {
3090- _keys : CK ,
3091- vals : Vec < CV > ,
3092- }
3093-
3094- impl < CK , CV : Len > Len for KeyMaps < CK , CV > {
3095- fn len ( & self ) -> usize {
3096- // This .. behaves badly if we have no keys.
3097- self . vals [ 0 ] . len ( )
3098- }
3099- }
3100-
3101- // Should this implementation preserve the order of the key-val pairs?
3102- // That might want an associated `Vec<usize>` for each, to order the keys.
3103- // If they are all identical, it shouldn't take up any space, though.
3104- impl < K : PartialOrd , V , CV : Push < K > > Push < Vec < ( K , V ) > > for KeyMaps < Vec < K > , CV > {
3105- #[ inline]
3106- fn push ( & mut self , _item : Vec < ( K , V ) > ) {
3107-
3108- }
3109- }
3110-
3111- /// A container for `Vec<K>` items sliced by index.
3112- ///
3113- /// The container puts each `item[i]` element into the `i`th column.
3114- pub struct ListMaps < CV > {
3115- vals : Vec < Options < CV > > ,
3116- }
3117-
3118- impl < CV > Default for ListMaps < CV > {
3119- fn default ( ) -> Self {
3120- ListMaps { vals : Default :: default ( ) }
3121- }
3122- }
3123-
3124- impl < CV : Len > Len for ListMaps < CV > {
3125- fn len ( & self ) -> usize {
3126- self . vals [ 0 ] . len ( )
3127- }
3128- }
3129-
3130- impl < ' a , V , CV : Push < & ' a V > + Len + Default > Push < & ' a Vec < V > > for ListMaps < CV > {
3131- #[ inline]
3132- fn push ( & mut self , item : & ' a Vec < V > ) {
3133- let mut item_len = item. len ( ) ;
3134- let self_len = if self . vals . is_empty ( ) { 0 } else { self . vals [ 0 ] . len ( ) } ;
3135- while self . vals . len ( ) < item_len {
3136- let mut new_store: Options < CV > = Default :: default ( ) ;
3137- for _ in 0 ..self_len {
3138- new_store. push ( None ) ;
3139- }
3140- self . vals . push ( new_store) ;
3141- }
3142- for ( store, i) in self . vals . iter_mut ( ) . zip ( item) {
3143- store. push ( Some ( i) ) ;
3144- }
3145- while item_len < self . vals . len ( ) {
3146- self . vals [ item_len] . push ( None ) ;
3147- item_len += 1 ;
3148- }
3149- }
3150- }
3151-
3152- #[ cfg( test) ]
3153- mod test {
3154-
3155- use crate :: common:: { Len , Push } ;
3156- use crate :: { Results , Strings } ;
3157-
3158- #[ test]
3159- fn round_trip_listmap ( ) {
3160-
3161- // Each record is a list, of first homogeneous elements, and one heterogeneous.
3162- let records = ( 0 .. 1024 ) . map ( |i|
3163- vec ! [
3164- Ok ( i) ,
3165- Err ( format!( "{:?}" , i) ) ,
3166- if i % 2 == 0 { Ok ( i) } else { Err ( format!( "{:?}" , i) ) } ,
3167- ]
3168- ) ;
3169-
3170- // We'll stash all the records in the store, which expects them.
3171- let mut store: super :: ListMaps < Results < Vec < i32 > , Strings > > = Default :: default ( ) ;
3172- for record in records {
3173- store. push ( & record) ;
3174- }
3175-
3176- // Demonstrate type-safe restructuring.
3177- // We expect the first two columns to be homogenous, and the third to be mixed.
3178- let field0: Option < & [ i32 ] > = if store. vals [ 0 ] . somes . oks . len ( ) == store. vals [ 0 ] . len ( ) {
3179- Some ( & store. vals [ 0 ] . somes . oks )
3180- } else { None } ;
3181-
3182- let field1: Option < & Strings > = if store. vals [ 1 ] . somes . errs . len ( ) == store. vals [ 1 ] . len ( ) {
3183- Some ( & store. vals [ 1 ] . somes . errs )
3184- } else { None } ;
3185-
3186- let field2: Option < & [ i32 ] > = if store. vals [ 2 ] . somes . oks . len ( ) == store. vals [ 2 ] . len ( ) {
3187- Some ( & store. vals [ 2 ] . somes . oks )
3188- } else { None } ;
3189-
3190- assert ! ( field0. is_some( ) ) ;
3191- assert ! ( field1. is_some( ) ) ;
3192- assert ! ( field2. is_none( ) ) ;
3193- }
3194- }
3195-
3196- }
3197-
3198- /// Containers for `isize` and `usize` that adapt to the size of the data.
3199- ///
3200- /// Similar structures could be used for containers of `u8`, `u16`, `u32`, and `u64`,
3201- /// without losing their type information, if one didn't need the bespoke compression.
3202- mod sizes {
3203-
3204- use crate :: Push ;
3205- use crate :: Results ;
3206-
3207- /// A four-variant container for integers of varying sizes.
3208- struct Sizes < C0 , C1 , C2 , C3 > {
3209- /// Four variants stored separately.
3210- inner : Results < Results < C0 , C1 > , Results < C2 , C3 > > ,
3211- }
3212-
3213- impl < C0 : Default , C1 : Default , C2 : Default , C3 : Default > Default for Sizes < C0 , C1 , C2 , C3 > {
3214- fn default ( ) -> Self {
3215- Sizes { inner : Default :: default ( ) }
3216- }
3217- }
3218-
3219- impl < C0 : Push < u8 > , C1 : Push < u16 > , C2 : Push < u32 > , C3 : Push < u64 > > Push < usize > for Sizes < C0 , C1 , C2 , C3 > {
3220- #[ inline]
3221- fn push ( & mut self , item : usize ) {
3222- if let Ok ( item) = TryInto :: < u8 > :: try_into ( item) {
3223- self . inner . push ( Ok ( Ok ( item) ) )
3224- } else if let Ok ( item) = TryInto :: < u16 > :: try_into ( item) {
3225- self . inner . push ( Ok ( Err ( item) ) )
3226- } else if let Ok ( item) = TryInto :: < u32 > :: try_into ( item) {
3227- self . inner . push ( Err ( Ok ( item) ) )
3228- } else if let Ok ( item) = TryInto :: < u64 > :: try_into ( item) {
3229- self . inner . push ( Err ( Err ( item) ) )
3230- } else {
3231- panic ! ( "usize exceeds bounds of u64" )
3232- }
3233- }
3234- }
3235-
3236- impl < C0 : Push < i8 > , C1 : Push < i16 > , C2 : Push < i32 > , C3 : Push < i64 > > Push < isize > for Sizes < C0 , C1 , C2 , C3 > {
3237- #[ inline]
3238- fn push ( & mut self , item : isize ) {
3239- if let Ok ( item) = TryInto :: < i8 > :: try_into ( item) {
3240- self . inner . push ( Ok ( Ok ( item) ) )
3241- } else if let Ok ( item) = TryInto :: < i16 > :: try_into ( item) {
3242- self . inner . push ( Ok ( Err ( item) ) )
3243- } else if let Ok ( item) = TryInto :: < i32 > :: try_into ( item) {
3244- self . inner . push ( Err ( Ok ( item) ) )
3245- } else if let Ok ( item) = TryInto :: < i64 > :: try_into ( item) {
3246- self . inner . push ( Err ( Err ( item) ) )
3247- } else {
3248- panic ! ( "isize exceeds bounds of i64" )
3249- }
3250- }
3251- }
3252- }
3253-
32543080/// Roaring bitmap (and similar) containers.
32553081pub mod roaring {
32563082
0 commit comments