Skip to content

Commit

Permalink
Update README, travis.yml, and badge icons
Browse files Browse the repository at this point in the history
  • Loading branch information
dghubble committed Nov 13, 2018
1 parent a6f3a86 commit cefab7d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ go:
- 1.8
- 1.9
- "1.10.x"
- "1.11.x"
- tip
install:
- go get golang.org/x/lint/golint
Expand Down
35 changes: 21 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Trie [![Build Status](https://travis-ci.org/dghubble/trie.png)](https://travis-ci.org/dghubble/trie) [![Coverage](https://gocover.io/_badge/github.com/dghubble/trie)](https://gocover.io/github.com/dghubble/trie) [![GoDoc](https://godoc.org/github.com/dghubble/trie?status.png)](https://godoc.org/github.com/dghubble/trie)
# Trie [![Build Status](https://travis-ci.org/dghubble/trie.svg)](https://travis-ci.org/dghubble/trie) [![Coverage](https://gocover.io/_badge/github.com/dghubble/trie)](https://gocover.io/github.com/dghubble/trie) [![GoDoc](https://godoc.org/github.com/dghubble/trie?status.svg)](https://godoc.org/github.com/dghubble/trie)

Trie implements several types of Tries (e.g. rune-wise, path-wise). The implementations are optimized for ``Get`` performance and to allocate 0 bytes of heap memory (i.e. garbage) per Get.
Package `trie` implements rune-wise and path-wise [Tries](https://en.wikipedia.org/wiki/Trie) optimized for `Get` performance and to allocate 0 bytes of heap memory (i.e. garbage) per `Get`.

The Tries do not synchronize access (not thread-safe). A typical use case is to perform ``Puts`` and ``Deletes`` upfront to populate the Trie, then perform ``Gets`` very quickly.
A typical use case is to perform any `Put` or `Delete` operations upfront to populate the trie, then perform `Get` operations very quickly. The Tries do not synchronize access (not thread-safe).

When Tries are chosen over maps, it is typically for their space efficiency. However, in situations where direct key lookup is not possible (e.g. routers), tries can provide faster lookups and avoid key iteration.

## Install

$ go get github.com/dghubble/trie
```
$ go get github.com/dghubble/trie
```

## Documentation

Expand All @@ -18,27 +20,32 @@ Read [Godoc](https://godoc.org/github.com/dghubble/trie)

RuneTrie is a typical Trie which segments strings rune-wise (i.e. by unicode code point). These benchmarks perform Puts and Gets of random string keys that are 30 bytes long and of random '/' separated paths that have 3 parts and are 30 bytes long (longer if you count the '/' seps).

BenchmarkRuneTriePutStringKey 2000000 653 ns/op 2 B/op 0 allocs/op
BenchmarkRuneTrieGetStringKey 5000000 616 ns/op 0 B/op 0 allocs/op
BenchmarkRuneTriePutPathKey 5000000 704 ns/op 1 B/op 0 allocs/op
BenchmarkRuneTrieGetPathKey 5000000 682 ns/op 0 B/op 0 allocs/op
```
BenchmarkRuneTriePutStringKey 2000000 653 ns/op 2 B/op 0 allocs/op
BenchmarkRuneTrieGetStringKey 5000000 616 ns/op 0 B/op 0 allocs/op
BenchmarkRuneTriePutPathKey 5000000 704 ns/op 1 B/op 0 allocs/op
BenchmarkRuneTrieGetPathKey 5000000 682 ns/op 0 B/op 0 allocs/op
```

PathTrie segments strings by forward slash separators which can boost performance
for some use cases. These benchmarks perform Puts and Gets of random string keys that are 30 bytes long and of random '/' separated paths that have 3 parts and are 30 bytes long (longer if you count the '/' seps).

BenchmarkPathTriePutStringKey 20000000 94.2 ns/op 0 B/op 0 allocs/op
BenchmarkPathTrieGetStringKey 20000000 93.5 ns/op 0 B/op 0 allocs/op
BenchmarkPathTriePutPathKey 20000000 113 ns/op 0 B/op 0 allocs/op
BenchmarkPathTrieGetPathKey 20000000 108 ns/op 0 B/op 0 allocs/op
```
BenchmarkPathTriePutStringKey 20000000 94.2 ns/op 0 B/op 0 allocs/op
BenchmarkPathTrieGetStringKey 20000000 93.5 ns/op 0 B/op 0 allocs/op
BenchmarkPathTriePutPathKey 20000000 113 ns/op 0 B/op 0 allocs/op
BenchmarkPathTrieGetPathKey 20000000 108 ns/op 0 B/op 0 allocs/op
```

Note that for random string Puts and Gets, the PathTrie is effectively a map as every node is a direct child of the root (except for strings that happen to have a slash).

This benchmark measures the performance of the PathSegmenter alone. It is used to segment random paths that have 3 '/' separated parts and are 30 bytes long.

BenchmarkPathSegmenter 50000000 58.8 ns/op 0 B/op 0 allocs/op
```
BenchmarkPathSegmenter 50000000 58.8 ns/op 0 B/op 0 allocs/op
```

## License

[MIT License](LICENSE)


0 comments on commit cefab7d

Please # to comment.