Skip to content

Commit

Permalink
update read me
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Gaetano Padula committed Oct 11, 2024
1 parent 20cb321 commit 234451a
Showing 1 changed file with 67 additions and 12 deletions.
79 changes: 67 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# GO BTree
A fast, simple persistent BTree implementation in Go.
A fast, simple disk based BTree implementation in Go.

https://pkg.go.dev/github.com/guycipher/btree

## Features
- Easy to use API with `Put`, `Get`, `Delete`, `Remove`, `Iterator`, `Range` methods
- Disk based storage
- Disk based storage with underlying pager
- Supports keys with multiple values
- Supports large keys and values

Expand All @@ -31,7 +31,7 @@ import "github.com/guycipher/btree"

You can use the ``Open`` method to open an existing btree or create a new one.
You can specify the file, permission and T(degree)
```
```go
// name of the file, flags, file mode, T(degree)
bt, err := btree.Open("btree.db", os.O_CREATE|os.O_RDWR, 0644, 3)
if err != nil {
Expand All @@ -42,7 +42,7 @@ if err != nil {
### Inserting a key-value pair

You can insert a value into a key using the ``Put`` method. Keys can store many values.
```
```go
err := bt.Put([]byte("key"), []byte("value"))
if err != nil {
..
Expand All @@ -52,17 +52,62 @@ if err != nil {
### Getting a value

To get a value you can you the ``Get`` method. The get method will return all the keys values.
```
```go
values, err := bt.Get([]byte("key"))
if err != nil {
..
}
```

#### NGet
To get all keys not equal to the key you can use the ``NGet`` method.
```go
keys, err := bt.NGet([]byte("key"))
if err != nil {
..
}
```

### GreaterThan
To get all keys greater than the key you can use the ``GreaterThan`` method.
```go
keys, err := bt.GreaterThan([]byte("key"))
if err != nil {
..
}
```

### GreaterThanEq
To get all keys greater than or equal to the key you can use the ``GreaterThanEq`` method.
```go
keys, err := bt.GreaterThanEq([]byte("key"))
if err != nil {
..
}
```

### LessThan
To get all keys less than the key you can use the ``LessThan`` method.
```go
keys, err := bt.LessThan([]byte("key"))
if err != nil {
..
}
```

### LessThanEq
To get all keys less than or equal to the key you can use the ``LessThanEq`` method.
```go
keys, err := bt.LessThanEq([]byte("key"))
if err != nil {
..
}
```

### Deleting a key

To delete a key and all of it's values you can use the ``Delete`` method.
```
```go
err := bt.Delete([]byte("key"))
if err != nil {
..
Expand All @@ -72,18 +117,18 @@ if err != nil {
### Removing a value within key

To remove a value from a key you can use the ``Remove`` method.
```
```go
err := bt.Remove([]byte("key"), []byte("value"))
if err != nil {
..
}
```

### Iterator
### Key Iterator

The iterator is used to iterate over values of a key

```
```go
iterator := key.Iterator()

for {
Expand All @@ -104,18 +149,28 @@ value3
```

### Range query
```
Get all keys between key1 and key3
```go
keys, err := bt.Range([]byte("key1"), []byte("key3"))
if err != nil {
..
}
```

### Not Range query
Get all keys not between key1 and key3
```go
keys, err := bt.NRange([]byte("key1"), []byte("key3"))
if err != nil {
..
}
```

### Closing the BTree

You can close the BTree by calling the Close function.

```
This will close the underlying file and free up resources.
```go
err := bt.Close()
if err != nil {
..
Expand Down

0 comments on commit 234451a

Please sign in to comment.