1
1
# GO BTree
2
- A fast, simple persistent BTree implementation in Go.
2
+ A fast, simple disk based BTree implementation in Go.
3
3
4
4
https://pkg.go.dev/github.com/guycipher/btree
5
5
6
6
## Features
7
7
- Easy to use API with ` Put ` , ` Get ` , ` Delete ` , ` Remove ` , ` Iterator ` , ` Range ` methods
8
- - Disk based storage
8
+ - Disk based storage with underlying pager
9
9
- Supports keys with multiple values
10
10
- Supports large keys and values
11
11
@@ -31,7 +31,7 @@ import "github.com/guycipher/btree"
31
31
32
32
You can use the `` Open `` method to open an existing btree or create a new one.
33
33
You can specify the file, permission and T(degree)
34
- ```
34
+ ``` go
35
35
// name of the file, flags, file mode, T(degree)
36
36
bt , err := btree.Open (" btree.db" , os.O_CREATE |os.O_RDWR , 0644 , 3 )
37
37
if err != nil {
@@ -42,7 +42,7 @@ if err != nil {
42
42
### Inserting a key-value pair
43
43
44
44
You can insert a value into a key using the `` Put `` method. Keys can store many values.
45
- ```
45
+ ``` go
46
46
err := bt.Put ([]byte (" key" ), []byte (" value" ))
47
47
if err != nil {
48
48
..
@@ -52,17 +52,62 @@ if err != nil {
52
52
### Getting a value
53
53
54
54
To get a value you can you the `` Get `` method. The get method will return all the keys values.
55
- ```
55
+ ``` go
56
56
values , err := bt.Get ([]byte (" key" ))
57
57
if err != nil {
58
58
..
59
59
}
60
60
```
61
61
62
+ #### NGet
63
+ To get all keys not equal to the key you can use the `` NGet `` method.
64
+ ``` go
65
+ keys , err := bt.NGet ([]byte (" key" ))
66
+ if err != nil {
67
+ ..
68
+ }
69
+ ```
70
+
71
+ ### GreaterThan
72
+ To get all keys greater than the key you can use the `` GreaterThan `` method.
73
+ ``` go
74
+ keys , err := bt.GreaterThan ([]byte (" key" ))
75
+ if err != nil {
76
+ ..
77
+ }
78
+ ```
79
+
80
+ ### GreaterThanEq
81
+ To get all keys greater than or equal to the key you can use the `` GreaterThanEq `` method.
82
+ ``` go
83
+ keys , err := bt.GreaterThanEq ([]byte (" key" ))
84
+ if err != nil {
85
+ ..
86
+ }
87
+ ```
88
+
89
+ ### LessThan
90
+ To get all keys less than the key you can use the `` LessThan `` method.
91
+ ``` go
92
+ keys , err := bt.LessThan ([]byte (" key" ))
93
+ if err != nil {
94
+ ..
95
+ }
96
+ ```
97
+
98
+ ### LessThanEq
99
+ To get all keys less than or equal to the key you can use the `` LessThanEq `` method.
100
+ ``` go
101
+ keys , err := bt.LessThanEq ([]byte (" key" ))
102
+ if err != nil {
103
+ ..
104
+ }
105
+ ```
106
+
62
107
### Deleting a key
63
108
64
109
To delete a key and all of it's values you can use the `` Delete `` method.
65
- ```
110
+ ``` go
66
111
err := bt.Delete ([]byte (" key" ))
67
112
if err != nil {
68
113
..
@@ -72,18 +117,18 @@ if err != nil {
72
117
### Removing a value within key
73
118
74
119
To remove a value from a key you can use the `` Remove `` method.
75
- ```
120
+ ``` go
76
121
err := bt.Remove ([]byte (" key" ), []byte (" value" ))
77
122
if err != nil {
78
123
..
79
124
}
80
125
```
81
126
82
- ### Iterator
127
+ ### Key Iterator
83
128
84
129
The iterator is used to iterate over values of a key
85
130
86
- ```
131
+ ``` go
87
132
iterator := key.Iterator ()
88
133
89
134
for {
@@ -104,18 +149,28 @@ value3
104
149
```
105
150
106
151
### Range query
107
- ```
152
+ Get all keys between key1 and key3
153
+ ``` go
108
154
keys , err := bt.Range ([]byte (" key1" ), []byte (" key3" ))
109
155
if err != nil {
110
156
..
111
157
}
112
158
```
113
159
160
+ ### Not Range query
161
+ Get all keys not between key1 and key3
162
+ ``` go
163
+ keys , err := bt.NRange ([]byte (" key1" ), []byte (" key3" ))
164
+ if err != nil {
165
+ ..
166
+ }
167
+ ```
168
+
114
169
### Closing the BTree
115
170
116
171
You can close the BTree by calling the Close function.
117
-
118
- ```
172
+ This will close the underlying file and free up resources.
173
+ ``` go
119
174
err := bt.Close ()
120
175
if err != nil {
121
176
..
0 commit comments