MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / add_line

Method add_line

atomic-core/src/record/workflow/crdt/builder/branch.rs:211–228  ·  view source on GitHub ↗

Adds a new line to a file and returns its branch ID. # Arguments `trunk_id` - The file to add the line to `after` - The branch to insert after (None for start of file)

(
        &mut self,
        trunk_id: crate::crdt::TrunkId,
        after: Option<BranchId>,
    )

Source from the content-addressed store, hash-verified

209 /// * `trunk_id` - The file to add the line to
210 /// * `after` - The branch to insert after (None for start of file)
211 pub fn add_line(
212 &mut self,
213 trunk_id: crate::crdt::TrunkId,
214 after: Option<BranchId>,
215 ) -> BranchId {
216 let branch_id = self.alloc_branch_id();
217
218 let line_op = LineOps::insert(branch_id, after, Vec::new());
219
220 if let Some(&file_idx) = self.trunk_index.get(&trunk_id) {
221 let line_idx = self.file_ops[file_idx].line_ops.len();
222 self.branch_index.insert(branch_id, (file_idx, line_idx));
223 self.file_ops[file_idx].add_line_op(line_op);
224 }
225
226 self.stats.lines_added += 1;
227 branch_id
228 }
229
230 /// Adds a line with content, tokenizing into leaves.
231 pub fn add_line_with_content(

Callers 4

test_builder_add_lineFunction · 0.45
test_builder_add_tokenFunction · 0.45
test_builder_last_branchFunction · 0.45
test_builder_last_leafFunction · 0.45

Calls 5

getMethod · 0.65
alloc_branch_idMethod · 0.45
lenMethod · 0.45
insertMethod · 0.45
add_line_opMethod · 0.45

Tested by 4

test_builder_add_lineFunction · 0.36
test_builder_add_tokenFunction · 0.36
test_builder_last_branchFunction · 0.36
test_builder_last_leafFunction · 0.36