-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
78 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions
22
Database/Sources/Database/Options.swift → Database/Sources/RocksDBSwift/Options.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,52 @@ | ||
import rocksdb | ||
import Utils | ||
|
||
public struct Options: ~Copyable, Sendable { | ||
struct Options: ~Copyable, Sendable { | ||
let ptr: SafePointer | ||
|
||
var value: OpaquePointer { ptr.value } | ||
|
||
public init() { | ||
init() { | ||
ptr = .init(ptr: rocksdb_options_create(), free: rocksdb_options_destroy) | ||
} | ||
|
||
public func increaseParallelism(cpus: Int) { | ||
func increaseParallelism(cpus: Int) { | ||
rocksdb_options_increase_parallelism(ptr.value, Int32(cpus)) | ||
} | ||
|
||
public func optimizeLevelStyleCompaction(memtableMemoryBudget: UInt64) { | ||
func optimizeLevelStyleCompaction(memtableMemoryBudget: UInt64) { | ||
rocksdb_options_optimize_level_style_compaction(ptr.value, memtableMemoryBudget) | ||
} | ||
|
||
public func setCreateIfMissing(_ createIfMissing: Bool) { | ||
func setCreateIfMissing(_ createIfMissing: Bool) { | ||
rocksdb_options_set_create_if_missing(ptr.value, createIfMissing ? 1 : 0) | ||
} | ||
|
||
public func setLevelCompactionDynamicLevelBytes(_ levelCompactionDynamicLevelBytes: Bool) { | ||
func setLevelCompactionDynamicLevelBytes(_ levelCompactionDynamicLevelBytes: Bool) { | ||
rocksdb_options_set_level_compaction_dynamic_level_bytes(ptr.value, levelCompactionDynamicLevelBytes ? 1 : 0) | ||
} | ||
|
||
public func setCreateIfMissingColumnFamilies(_ createIfMissingColumnFamilies: Bool) { | ||
func setCreateIfMissingColumnFamilies(_ createIfMissingColumnFamilies: Bool) { | ||
rocksdb_options_set_create_missing_column_families(ptr.value, createIfMissingColumnFamilies ? 1 : 0) | ||
} | ||
} | ||
|
||
public struct WriteOptions: ~Copyable, Sendable { | ||
struct WriteOptions: ~Copyable, Sendable { | ||
let ptr: SafePointer | ||
|
||
var value: OpaquePointer { ptr.value } | ||
|
||
public init() { | ||
init() { | ||
ptr = .init(ptr: rocksdb_writeoptions_create(), free: rocksdb_writeoptions_destroy) | ||
} | ||
} | ||
|
||
public struct ReadOptions: ~Copyable, Sendable { | ||
struct ReadOptions: ~Copyable, Sendable { | ||
let ptr: SafePointer | ||
|
||
var value: OpaquePointer { ptr.value } | ||
|
||
public init() { | ||
init() { | ||
ptr = .init(ptr: rocksdb_readoptions_create(), free: rocksdb_readoptions_destroy) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Foundation | ||
|
||
public protocol StoreCoder<Key, Value>: Sendable { | ||
associatedtype Key: Encodable | ||
associatedtype Value: Decodable | ||
|
||
func encode(key: Key) throws -> Data | ||
func decode(data: Data) throws -> Value | ||
} | ||
|
||
public final class Store<CFKey: ColumnFamilyKey, Coder: StoreCoder>: Sendable { | ||
private let db: RocksDB<CFKey> | ||
private let column: CFKey | ||
private let coder: Coder | ||
|
||
public init(db: RocksDB<CFKey>, column: CFKey, coder: Coder) { | ||
self.db = db | ||
self.column = column | ||
self.coder = coder | ||
} | ||
|
||
public func get(key: Coder.Key) throws -> Coder.Value? { | ||
let encodedKey = try coder.encode(key: key) | ||
|
||
let data = try db.get(column: column, key: encodedKey) | ||
|
||
return try data.map { try coder.decode(data: $0) } | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters