diff options
Diffstat (limited to 'src/document/bench.rs')
| -rw-r--r-- | src/document/bench.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/document/bench.rs b/src/document/bench.rs index 02b530d..908f919 100644 --- a/src/document/bench.rs +++ b/src/document/bench.rs @@ -29,6 +29,41 @@ fn sorted(mut heads: Vec<ChangeHash>) -> Vec<ChangeHash> { heads } +/// `count` changes to `doc`, each writing one key under `data` (from `first` on), made +/// at `at` and after. +pub(crate) fn writes(doc: &mut Document, first: usize, count: usize, at: i64) { + for i in 0..count { + let mut transaction = doc.transaction(); + let data = transaction + .get(ROOT, "data") + .expect("read") + .map(|(_, id)| id) + .unwrap_or_else(|| { + transaction + .put_object(ROOT, "data", automerge::ObjType::Map) + .expect("map") + }); + transaction + .put( + &data, + format!("late{}", first + i), + ScalarValue::Int(i as i64), + ) + .expect("write"); + transaction + .commit_with(automerge::transaction::CommitOptions::default().with_time(at + i as i64)); + } +} + +/// A new document holding what `of` holds, as one change at time 0 (a snapshot). +pub(crate) fn snapshot(of: &Document) -> Document { + let mut new = Document::new(); + let mut transaction = new.transaction(); + store::materialize_into(of, &mut transaction, &|_| false).expect("snapshot"); + transaction.commit_with(automerge::transaction::CommitOptions::default().with_time(0)); + new +} + /// A document with `keys` keys under `data`, each written by a change of its own. pub(crate) fn document(keys: usize) -> Document { let mut doc = Document::new(); |
