Opening A Tree

ZoneTree instances are created withZoneTreeFactory<TKey, TValue>. The factory collects configuration and opens or creates the underlying storage.

Open Or Create

using ZoneTree;

using var zoneTree = new ZoneTreeFactory<int, string>()
    .SetDataDirectory("data/app")
    .OpenOrCreate();

UseOpenOrCreatefor normal application startup when the database may or may not already exist.

Create

using var zoneTree = new ZoneTreeFactory<int, string>()
    .SetDataDirectory("data/app")
    .Create();

UseCreatewhen a database must not already exist.

Open Existing

using var zoneTree = new ZoneTreeFactory<int, string>()
    .SetDataDirectory("data/app")
    .Open();

UseOpenwhen an existing database is required.

Transactional Tree

using var zoneTree = new ZoneTreeFactory<int, string>()
    .SetDataDirectory("data/tx-app")
    .OpenOrCreateTransactional();

Transactional trees support coordinated multi-key operations. Use a non-transactional tree for the fastest simple read/write workloads.

Configure Before Opening

Set serializers, comparers, WAL options, deletion delegates, and storage options before opening the tree. These choices define the storage format and behavior.

using ZoneTree;
using ZoneTree.Comparers;
using ZoneTree.Serializers;

using var zoneTree = new ZoneTreeFactory<int, string>()
    .SetDataDirectory("data/app")
    .SetComparer(new Int32ComparerAscending())
    .SetKeySerializer(new Int32Serializer())
    .SetValueSerializer(new Utf8StringSerializer())
    .SetMutableSegmentMaxItemCount(100_000)
    .OpenOrCreate();

Dispose

Always dispose ZoneTree instances when the application is done with them.

using var zoneTree = new ZoneTreeFactory<int, string>()
    .SetDataDirectory("data/app")
    .OpenOrCreate();

For long-running services, keep the tree open for the service lifetime and dispose during shutdown.