simerplaha / SwayDB

Persistent and in-memory key-value storage engine for JVM that scales on a single machine.
https://swaydb.simer.au
Apache License 2.0
293 stars 16 forks source link

`Immutable` data structures #353

Open simerplaha opened 2 years ago

simerplaha commented 2 years ago

Support immutable data-structures.

Config

Being less complicated, Immutable data types can very easily be preconfigured to allow high performance in all areas so they should be supported internally.

Stream API

Updating existing data in an immutable data-structure should automatically create different queryable versions.

//example version stream API
map
  .get(key)
  .versions
  .foreach {
    case (key, value, version) => 
       //do something
  }

Creating data-structures API

Following similar API as Scala collections.

//in Scala collections we can create a map as following
val map = mutable.Map.empty[Int, String]

Following above In SwayDB this should be

//mutable
val map = mutable.persistent.Map[Int, String, Nothing, Glass](dir = "my_map")
//or immutable
val map = immutable.persistent.Map[Int, String, Nothing, Glass](dir = "my_map")

In Java this would be

//mutable
Map<Integer, String, Void> map =
  MutablePersistentMap
    .functionsOff(Paths.get("my_map"), intSerializer(), stringSerializer())
    .get();

//or immutable
Map<Integer, String, Void> map =
 ImmutablePersistentMap
    .functionsOff(Paths.get("my_map"), intSerializer(), stringSerializer())
    .get();