simerplaha / SwayDB

Persistent and in-memory key-value storage engine for JVM that scales on a single machine.

Home Page:https://swaydb.simer.au

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Immutable` data structures

simerplaha opened this issue · comments

commented

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();