GitHub top language Latest Version Rust Documentation GitHub Workflow Status Minimum rustc version

VSDB

VSDB is a 'Git' in the form of KV-database.

Based on the powerful version control function of VSDB, you can easily give your data structure the ability to version management.

Make everything versioned !!

To view the change log check here.

Highlights

Examples

Suppose you have a great algorithm like this:

rust struct GreatAlgo { a: Vec<...>, b: BTreeMap<...>, c: u128, d: HashMap<...>, e: ... }

Simply replace the original structure with the corresponding VSDB data structure, and your algorithm get the powerful version control ability at once!

```rust

[dervive(Vs, Default)]

struct GreatAlgo { a: VecxVs<...>, b: MapxOrdVs<...>, c: OrphanVs, d: MapxVs<...>, e: ... }

let algo = GreatAlgo::default();

algo.getbybranchversion(...); algo.branchcreate(...); algo.branchcreatebybasebranch(...); algo.branchcreatebybasebranchversion(...); algo.branchremove(...); algo.version_pop(...); algo.prune(); ```

NOTE !!

the #[derive(Vs)] macro can be applied to structures whose internal fields are all types defined in VSDB (primitive types and their collections are also supported), but can not be applied to nesting wrapper among VSDB-types, we recommend you to use the multi-key APIs if you indeed require these functions(better performance also), or you will have to implement the VsMgmt trait manually.

This data structure can be handled correctly by #[derive(Vs)]:

```rust

[derive(Vs)]

struct GoodCase { a: VecxVs, b: SubItem0, c: SubItem1, d: SubItem2, e: u8, f: Vec, g: VecDeque, h: BTreeSet, i: HashMap, j: HashSet, k: LinkedList<()>, l: Box, m: Box]>>, n: PhantomData, }

[derive(Vs)]

struct SubItem0(MapxVs, VecxVs);

[derive(Vs)]

struct SubItem1 { a: OrphanVs, b: MapxOrdVs }

[derive(Vs)]

struct SubItem2 { a: i8, b: u128 }

// // A nope implementation of VsMgmt for custom stateless types. // // the #[derive(Vs)] on 'SubItem2' is same as this implementation. // impl VsMgmt for SubItem2 { // implvsmethods_nope!(); // } ```

But this one can NOT be handled correctly by #[derive(Vs)]:

```rust // It can be compiled, but the result is wrong ! // The versioned methods of the inner 'MapxVs' will missing, // We recommend you to use the 'multi-key' APIs of VSDB, or // you will have to implement the 'VsMgmt' trait manually.

[derive(Vs)]

struct BadCase { a: VecxVs>, } ```

Please check the multi-key functions if you have requirements of the above or similar scenes.

Some complete examples:

Compilation features

Low-level design

Based on the underlying one-dimensional linear storage structure (native kv-database, such as sled/rocksdb, etc.), multiple different namespaces are divided, and then abstract each dimension in the multi-dimensional logical structure based on these divided namespaces.

In the category of kv-database, namespaces can be expressed as different key ranges, or different key prefix.

This is the same as expressing complex data structures in computer memory(the memory itself is just a one-dimensional linear structure).

User data will be divided into two dimensions: 'branch' and 'version', the functions of the 'basic' category are stateless, and the functions of the 'versioned' category are stateful. In the internal implementation, each stateful function is implemented based on its corresponding stateless function, all stateful data has two additional identification dimensions ('branch' and 'version'), somewhat like the logic in Git. Stateless functions do not have the feature of 'version' management, but they have higher performance.

NOTE