@@ -360,9 +360,8 @@ ref_type ArrayMixed::typed_write(ref_type top_ref, _impl::ArrayWriterBase& out,
360360 2. int and pair int arrays, they are used for storing integers, timestamps, floats, doubles,
361361 decimals, links. In general we can compress them, but we need to be careful, controlling the col_type
362362 should prevent compressing data that we want to leave in the current format.
363- 3. string array is for strings and binary data (no compression for now)
364- 4. ref array is actually storing refs to collections. they can only be BPlusTree<int, Mixed> or
365- BPlusTree<string, Mixed>.
363+ 3. string array is for strings and binary data
364+ 4. ref array is actually storing refs to collections. They can only be Lst<Mixed> or Dictionary.
366365 5. key array stores unique identifiers for collections in mixed (integers that can be compressed)
367366 */
368367 Array composite (alloc);
@@ -372,41 +371,48 @@ ref_type ArrayMixed::typed_write(ref_type top_ref, _impl::ArrayWriterBase& out,
372371 auto ref = top.get (i);
373372 ref_type new_ref = ref;
374373 if (ref && !(out.only_modified && alloc.is_read_only (ref))) {
375- if (i < 3 ) { // int, and pair_int
376- // integer arrays
377- new_ref = Array::write (ref, alloc, out, out.only_modified , out.compress );
378- }
379- else if (i == 4 ) { // collection in mixed
380- ArrayRef arr_ref (alloc);
381- arr_ref.init_from_ref (ref);
382- auto ref_sz = arr_ref.size ();
383- TempArray written_ref_leaf (ref_sz);
384-
385- for (size_t k = 0 ; k < ref_sz; k++) {
386- ref_type new_sub_ref = 0 ;
387- if (auto sub_ref = arr_ref.get (k)) {
388- auto header = alloc.translate (sub_ref);
389- // Now we have to find out if the nested collection is a
390- // dictionary or a list. If the top array has a size of 2
391- // and it is not a BplusTree inner node, then it is a dictionary
392- if (NodeHeader::get_size_from_header (header) == 2 &&
393- !NodeHeader::get_is_inner_bptree_node_from_header (header)) {
394- new_sub_ref = Dictionary::typed_write (sub_ref, out, alloc);
395- }
396- else {
397- new_sub_ref = BPlusTree<Mixed>::typed_write (sub_ref, out, alloc);
374+ switch (i) {
375+ case payload_idx_int:
376+ // integer array
377+ new_ref = Array::write (ref, alloc, out, out.only_modified , out.compress );
378+ break ;
379+ case payload_idx_pair:
380+ // integer array
381+ new_ref = Array::write (ref, alloc, out, out.only_modified , out.compress );
382+ break ;
383+ case payload_idx_str:
384+ new_ref = ArrayString::typed_write (ref, out, alloc);
385+ break ;
386+ case payload_idx_ref: {
387+ // collection in mixed
388+ ArrayRef arr_ref (alloc);
389+ arr_ref.init_from_ref (ref);
390+ auto ref_sz = arr_ref.size ();
391+ TempArray written_ref_leaf (ref_sz);
392+
393+ for (size_t k = 0 ; k < ref_sz; k++) {
394+ ref_type new_sub_ref = 0 ;
395+ if (auto sub_ref = arr_ref.get (k)) {
396+ auto header = alloc.translate (sub_ref);
397+ // Now we have to find out if the nested collection is a
398+ // dictionary or a list. If the top array has a size of 2
399+ // and it is not a BplusTree inner node, then it is a dictionary
400+ if (NodeHeader::get_size_from_header (header) == 2 &&
401+ !NodeHeader::get_is_inner_bptree_node_from_header (header)) {
402+ new_sub_ref = Dictionary::typed_write (sub_ref, out, alloc);
403+ }
404+ else {
405+ new_sub_ref = BPlusTree<Mixed>::typed_write (sub_ref, out, alloc);
406+ }
398407 }
408+ written_ref_leaf.set_as_ref (k, new_sub_ref);
399409 }
400- written_ref_leaf.set_as_ref (k, new_sub_ref);
410+ new_ref = written_ref_leaf.write (out);
411+ break ;
401412 }
402- new_ref = written_ref_leaf.write (out);
403- }
404- else if (i == 5 ) { // unique keys associated to collections in mixed
405- new_ref = Array::write (ref, alloc, out, out.only_modified , out.compress );
406- }
407- else {
408- // all the rest we don't want to compress it, at least for now (strings will be needed)
409- new_ref = Array::write (ref, alloc, out, out.only_modified , false );
413+ case payload_idx_key:
414+ new_ref = Array::write (ref, alloc, out, out.only_modified , out.compress );
415+ break ;
410416 }
411417 }
412418 written_leaf.set (i, new_ref);
0 commit comments