Skip to content

Commit 96e5666

Browse files
committed
Create interface.go
1 parent 31fa52e commit 96e5666

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

interface.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package ogdb
2+
3+
// Code using batches should try to add this much data to the batch.
4+
// The value was determined empirically.
5+
const IdealBatchSize = 100 * 1024
6+
7+
// Putter wraps the database write operation supported by both batches and regular databases.
8+
type Putter interface {
9+
Put(key []byte, value []byte) error
10+
}
11+
12+
// Database wraps all database operations. All methods are safe for concurrent use.
13+
type Database interface {
14+
Putter
15+
Get(key []byte) ([]byte, error)
16+
Has(key []byte) (bool, error)
17+
Delete(key []byte) error
18+
Close()
19+
NewBatch() Batch
20+
}
21+
22+
// Batch is a write-only database that commits changes to its host database
23+
// when Write is called. Batch cannot be used concurrently.
24+
type Batch interface {
25+
Putter
26+
ValueSize() int // amount of data in the batch
27+
Write() error
28+
// Reset resets the batch for reuse
29+
Reset()
30+
}

0 commit comments

Comments
 (0)