@@ -19,8 +19,6 @@ mod validity;
1919mod varbinview;
2020mod vector;
2121
22- use bitvec:: prelude:: Lsb0 ;
23- use bitvec:: view:: BitView ;
2422pub use cache:: ConversionCache ;
2523pub use decimal:: precision_to_duckdb_storage_size;
2624use vortex:: array:: ArrayRef ;
@@ -187,19 +185,6 @@ fn new_array_exporter_with_flatten(
187185 }
188186}
189187
190- /// Copy the sliced bits from source into target.
191- ///
192- /// Offset and length are a _bit_ offset and a _bit_ length into source.
193- ///
194- /// `target.len()` must equal `len`.
195- fn copy_from_slice ( target : & mut [ u64 ] , source : & [ u8 ] , offset : usize , len : usize ) {
196- let ( start, middle, end) = unsafe { target. align_to_mut :: < u8 > ( ) } ;
197- assert ! ( start. is_empty( ) ) ;
198- assert ! ( end. is_empty( ) ) ;
199- let target = & mut middle. view_bits_mut :: < Lsb0 > ( ) [ ..len] ;
200- target. copy_from_bitslice ( & source. view_bits ( ) [ offset..] [ ..len] ) ;
201- }
202-
203188#[ cfg( test) ]
204189mod tests {
205190 use vortex:: buffer:: BitBuffer ;
@@ -208,7 +193,6 @@ mod tests {
208193 use crate :: cpp:: DUCKDB_TYPE ;
209194 use crate :: duckdb:: LogicalType ;
210195 use crate :: duckdb:: Vector ;
211- use crate :: exporter:: copy_from_slice;
212196
213197 #[ test]
214198 fn test_set_validity_all_true ( ) {
@@ -355,178 +339,4 @@ mod tests {
355339 }
356340 }
357341
358- #[ test]
359- fn test_copy_from_slice_empty_to_empty ( ) {
360- let target = & mut [ ] ;
361- let source = Vec :: < u8 > :: new ( ) ;
362- copy_from_slice ( target, & source, 0 , 0 ) ;
363- }
364-
365- #[ test]
366- fn test_copy_from_slice_64_to_empty ( ) {
367- let target = & mut [ ] ;
368- let source = [ 1u8 , 2 , 3 , 50 , 51 , 52 , 100 , 101 ] ;
369- copy_from_slice ( target, & source, 0 , 0 ) ;
370- copy_from_slice ( target, & source, 5 , 0 ) ;
371- copy_from_slice ( target, & source, 8 , 0 ) ;
372- }
373-
374- #[ test]
375- fn test_copy_from_slice_64_to_64 ( ) {
376- let mut target = vec ! [ 0u64 ] ;
377- let source = [ 1u8 , 2 , 3 , 50 , 51 , 52 , 100 , 101 ] ;
378- copy_from_slice ( & mut target, & source, 0 , 64 ) ;
379- assert_eq ! (
380- target[ 0 ] , 0x65_64_34_33_32_03_02_01_u64 ,
381- "{:#08x} == {:#08x}" ,
382- target[ 0 ] , 0x65_64_34_33_32_03_02_01_u64 ,
383- ) ;
384- }
385-
386- #[ test]
387- fn test_copy_from_slice_80_to_0 ( ) {
388- let target = & mut [ ] ;
389- let source = [ 1u8 , 2 , 3 , 50 , 51 , 52 , 100 , 101 , 254 , 255 ] ;
390- copy_from_slice ( target, & source, 0 , 0 ) ;
391- copy_from_slice ( target, & source, 8 , 0 ) ;
392- copy_from_slice ( target, & source, 10 , 0 ) ;
393- }
394-
395- #[ test]
396- fn test_copy_from_slice_80_to_64_case_1 ( ) {
397- let mut target = [ 0u64 ] ;
398- let source = [ 1u8 , 2 , 3 , 50 , 51 , 52 , 100 , 101 , 254 , 255 ] ;
399- copy_from_slice ( & mut target, & source, 16 , 64 ) ;
400- assert_eq ! (
401- target[ 0 ] , 0xff_fe_65_64_34_33_32_03_u64 ,
402- "{:#08x} == {:#08x}" ,
403- target[ 0 ] , 0xff_fe_65_64_34_33_32_03_u64 ,
404- ) ;
405- }
406-
407- #[ test]
408- fn test_copy_from_slice_80_to_64_case_2 ( ) {
409- let mut target = [ 0u64 ] ;
410- let source = [ 1u8 , 2 , 3 , 50 , 51 , 52 , 100 , 101 , 254 , 255 ] ;
411- copy_from_slice ( & mut target, & source, 8 , 64 ) ;
412- assert_eq ! (
413- target[ 0 ] , 0xfe_65_64_34_33_32_03_02_u64 ,
414- "{:#08x} == {:#08x}" ,
415- target[ 0 ] , 0xfe_65_64_34_33_32_03_02_u64 ,
416- ) ;
417- }
418-
419- #[ test]
420- fn test_copy_from_slice_80_to_64_case_3 ( ) {
421- let mut target = [ 0u64 ] ;
422- let source = [ 1u8 , 2 , 3 , 50 , 51 , 52 , 100 , 101 , 254 , 255 ] ;
423- copy_from_slice ( & mut target, & source, 0 , 64 ) ;
424- assert_eq ! (
425- target[ 0 ] , 0x65_64_34_33_32_03_02_01_u64 ,
426- "{:#08x} == {:#08x}" ,
427- target[ 0 ] , 0x65_64_34_33_32_03_02_01_u64 ,
428- ) ;
429- }
430-
431- #[ test]
432- fn test_copy_from_slice_80_to_64_case_4 ( ) {
433- let mut target = [ 0u64 ] ;
434- let source = [ 1u8 , 2 , 3 , 50 , 51 , 52 , 100 , 101 , 254 , 255 ] ;
435- copy_from_slice ( & mut target, & source, 10 , 64 ) ;
436- assert_eq ! (
437- target[ 0 ] ,
438- 0xff_99_59_0d_0c_cc_80_c0_u64 , // Python: hex(0xff_fe_65_64_34_33_32_03_02 >> 2), then remove the high two hexits
439- "{:#08x} == {:#08x}" ,
440- target[ 0 ] ,
441- 0xff_99_59_0d_0c_cc_80_c0_u64
442- ) ;
443- }
444-
445- #[ test]
446- fn test_copy_from_slice_248_to_128_middle_non_empty ( ) {
447- let mut target = [ 0u64 , 0u64 ] ;
448- let source: [ u8 ; 31 ] = [
449- 0x01 , 0x02 , 0x03 , 0x04 , 0xff , 0xfe , 0xfd , 0xfc , 0x05 , 0x06 , 0x07 , 0x08 , 0xfc , 0xfb ,
450- 0xfa , 0xf9 , 0x01 , 0x02 , 0x03 , 0x04 , 0xff , 0xfe , 0xfd , 0xfc , 0x05 , 0x06 , 0x07 , 0x08 ,
451- 0xfc , 0xfb , 0xfa ,
452- ] ;
453- // In a span of 248 bits (31 bytes) there should be at least one 8-byte aligned span.
454- let ( _, middle, _) = unsafe { source. align_to :: < u64 > ( ) } ;
455- assert ! ( !middle. is_empty( ) ) ;
456-
457- copy_from_slice ( & mut target, & source, 0 , 128 ) ;
458- assert_eq ! (
459- target[ 0 ] , 0xfc_fd_fe_ff_04_03_02_01_u64 ,
460- "{:#08x} == {:#08x}" ,
461- target[ 0 ] , 0xfc_fd_fe_ff_04_03_02_01_u64 ,
462- ) ;
463- assert_eq ! (
464- target[ 1 ] , 0xf9_fa_fb_fc_08_07_06_05_u64 ,
465- "{:#08x} == {:#08x}" ,
466- target[ 1 ] , 0xf9_fa_fb_fc_08_07_06_05_u64 ,
467- ) ;
468-
469- copy_from_slice ( & mut target, & source, 8 , 128 ) ;
470- assert_eq ! (
471- target[ 0 ] , 0x05_fc_fd_fe_ff_04_03_02_u64 ,
472- "{:#08x} == {:#08x}" ,
473- target[ 0 ] , 0x05_fc_fd_fe_ff_04_03_02_u64 ,
474- ) ;
475- assert_eq ! (
476- target[ 1 ] , 0x01_f9_fa_fb_fc_08_07_06_u64 ,
477- "{:#08x} == {:#08x}" ,
478- target[ 1 ] , 0x01_f9_fa_fb_fc_08_07_06_u64 ,
479- ) ;
480-
481- copy_from_slice ( & mut target, & source, 8 * 8 , 128 ) ;
482- assert_eq ! (
483- target[ 0 ] , 0xf9_fa_fb_fc_08_07_06_05_u64 ,
484- "{:#08x} == {:#08x}" ,
485- target[ 0 ] , 0xf9_fa_fb_fc_08_07_06_05_u64 ,
486- ) ;
487- assert_eq ! (
488- target[ 1 ] , 0xfc_fd_fe_ff_04_03_02_01_u64 ,
489- "{:#08x} == {:#08x}" ,
490- target[ 1 ] , 0xfc_fd_fe_ff_04_03_02_01_u64 ,
491- ) ;
492-
493- copy_from_slice ( & mut target, & source, 8 * 12 , 128 ) ;
494- assert_eq ! (
495- target[ 0 ] , 0x04_03_02_01_f9_fa_fb_fc_u64 ,
496- "{:#08x} == {:#08x}" ,
497- target[ 0 ] , 0x04_03_02_01_f9_fa_fb_fc_u64 ,
498- ) ;
499- assert_eq ! (
500- target[ 1 ] , 0x08_07_06_05_fc_fd_fe_ff_u64 ,
501- "{:#08x} == {:#08x}" ,
502- target[ 1 ] , 0x08_07_06_05_fc_fd_fe_ff_u64 ,
503- ) ;
504-
505- copy_from_slice ( & mut target, & source, 8 * 12 + 4 , 128 ) ;
506- // Find the 12th byte, skip the first hexit, take the next 32 hexits (i.e. 16 bytesor 128
507- // bits).
508- assert_eq ! (
509- target[ 0 ] , 0xf0_40_30_20_1f_9f_af_bf_u64 ,
510- "{:#08x} == {:#08x}" ,
511- target[ 0 ] , 0xf0_40_30_20_1f_9f_af_bf_u64 ,
512- ) ;
513- assert_eq ! (
514- target[ 1 ] , 0xc0_80_70_60_5f_cf_df_ef_u64 ,
515- "{:#08x} == {:#08x}" ,
516- target[ 1 ] , 0xc0_80_70_60_5f_cf_df_ef_u64 ,
517- ) ;
518-
519- // Take the above and shift one bit towards the right-hand-side.
520- copy_from_slice ( & mut target, & source, 8 * 12 + 4 + 1 , 128 ) ;
521- assert_eq ! (
522- target[ 0 ] , 0xf8_20_18_10_0f_cf_d7_df_u64 ,
523- "{:#08x} == {:#08x}" ,
524- target[ 0 ] , 0xf8_20_18_10_0f_cf_d7_df_u64 ,
525- ) ;
526- assert_eq ! (
527- target[ 1 ] , 0xe0_40_38_30_2f_e7_ef_f7_u64 ,
528- "{:#08x} == {:#08x}" ,
529- target[ 1 ] , 0xe0_40_38_30_2f_e7_ef_f7_u64 ,
530- ) ;
531- }
532342}
0 commit comments