MCPcopy Create free account
hub / github.com/cosdata/cosdata / deserialize

Method deserialize

src/models/serializer/tree_map/versioned_vec.rs:72–148  ·  view source on GitHub ↗
(
        _dim_bufman: &BufferManager,
        data_bufmans: &BufferManagerFactory<VersionNumber>,
        file_offset: FileOffset,
        version: VersionNumber,
    )

Source from the content-addressed store, hash-verified

70 }
71
72 fn deserialize(
73 _dim_bufman: &BufferManager,
74 data_bufmans: &BufferManagerFactory<VersionNumber>,
75 file_offset: FileOffset,
76 version: VersionNumber,
77 ) -> Result<Self, BufIoError> {
78 let mut version_data: HashMap<VersionNumber, (FileOffset, Vec<u64>, VersionNumber)> =
79 HashMap::new();
80 let mut current_offset = file_offset;
81 let mut current_version = version;
82
83 // Read all versions into version_data
84 while current_offset.0 != u32::MAX {
85 let bufman = data_bufmans.get(current_version)?;
86 let cursor = bufman.open_cursor()?;
87 bufman.seek_with_cursor(cursor, current_offset.0 as u64)?;
88 let next_offset = FileOffset(bufman.read_u32_with_cursor(cursor)?);
89 let next_version = VersionNumber::from(bufman.read_u32_with_cursor(cursor)?);
90 let version = VersionNumber::from(bufman.read_u32_with_cursor(cursor)?);
91 let len = bufman.read_u32_with_cursor(cursor)? as usize;
92 let mut list = Vec::with_capacity(len);
93 for _ in 0..len {
94 list.push(bufman.read_u64_with_cursor(cursor)?);
95 }
96 version_data.insert(version, (current_offset, list, next_version));
97 current_offset = next_offset;
98 current_version = next_version;
99 bufman.close_cursor(cursor)?;
100 }
101
102 // Collect delete operations
103 let mut deletes = Vec::new();
104 for (_, list, _) in version_data.values() {
105 for &item in list {
106 if (item & (1 << 63)) != 0 {
107 let target_version = VersionNumber::from(((item >> 32) & 0x7FFFFFFF) as u32);
108 let target_index = (item & 0xFFFFFFFF) as usize;
109 deletes.push((target_version, target_index));
110 }
111 }
112 }
113
114 // Apply delete operations
115 for (target_version, target_index) in deletes {
116 if let Some((_, target_list, _)) = version_data.get_mut(&target_version) {
117 if target_index < target_list.len() {
118 target_list[target_index] = u64::MAX;
119 }
120 }
121 }
122
123 // Build the VersionedVec chain
124 let mut versions = Vec::new();
125 let mut current_version = version;
126 while let Some((_, _, next_version)) = version_data.get(&current_version) {
127 versions.push(current_version);
128 if *next_version == VersionNumber::from(u32::MAX) {
129 break;

Callers

nothing calls this directly

Calls 13

FileOffsetClass · 0.85
open_cursorMethod · 0.80
seek_with_cursorMethod · 0.80
read_u32_with_cursorMethod · 0.80
read_u64_with_cursorMethod · 0.80
close_cursorMethod · 0.80
valuesMethod · 0.80
removeMethod · 0.80
getMethod · 0.45
pushMethod · 0.45
insertMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected