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

Method deserialize

src/models/serializer/inverted/versioned_vec.rs:73–150  ·  view source on GitHub ↗
(
        _dim_bufman: &BufferManager,
        data_bufmans: &BufferManagerFactory<VersionNumber>,
        file_offset: FileOffset,
        version: VersionNumber,
        _cache: &InvertedIndexCache,

Source from the content-addressed store, hash-verified

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

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