<commit_before># Go segtree

A [segment tree](http://en.wikipedia.org/wiki/Segment_tree) implementation written in Go.

This library allows storing and retrieving elements indexed by a range. It does this by storing the elements in a segment tree.

Based on:
- [go-stree](https://github.com/toberndo/go-stree) by @toberndo
- Chapter 10.3 of [Computational Geometry: Algorithms and Applications](http://www.cs.uu.nl/geobook/) rev. 3 by <NAME>, <NAME>, <NAME> and <NAME> (ISBN [978-3-540-77973-5](http://link.springer.com/book/10.1007%2F978-3-540-77974-2))

The elements are sent to a channel as soon as they are found in the tree. This allows efficient querying of e.g multi-dimensional trees (trees containing trees). The elements are not sent in any specific order, however each found element will only be sent once.

# Example usages:

```go
tree := new(segtree.Tree)
tree.Push(1, 10, "hello, world")
tree.BuildTree()

results, err := tree.QueryIndex(4)
if err != nil {
	panic(fmt.Sprintf("Failed to query tree: %s", err.Error()))
}

result := <-results
fmt.Println("Found:", result)
```

An exemplary 2-dimensional segment tree as a tree in a tree:
```go
inner := new(segtree.Tree)
inner.Push(1, 10, "hello, world")
inner.BuildTree()

outer := new(Tree)
outer.Push(0, 99, inner)<commit_msg>Small improvements to README<commit_after># Go segtree

A [segment tree](http://en.wikipedia.org/wiki/Segment_tree) implementation written in Go.

This library allows storing and retrieving elements indexed by a range. It does this by storing the elements in a segment tree.

Based on:
- [go-stree](https://github.com/toberndo/go-stree) by @toberndo
- Chapter 10.3 of [Computational Geometry: Algorithms and Applications](http://www.cs.uu.nl/geobook/) rev. 3 by <NAME>, <NAME>, <NAME> and <NAME> (ISBN [978-3-540-77973-5](http://link.springer.com/book/10.1007%2F978-3-540-77974-2))

The elements are sent on a channel as soon as they are found in the tree. This allows efficient querying of e.g multi-dimensional trees (trees containing trees). The elements are not sent in any specific order, however each found element will only be sent once.

## Example usages:

```go
tree := new(segtree.Tree)
tree.Push(1, 10, "hello, world")
tree.BuildTree()

results, err := tree.QueryIndex(4)
if err != nil {
	panic(fmt.Sprintf("Failed to query tree: %s", err.Error()))
}

result := <-results
fmt.Println("Found:", result)
```

An exemplary 2-dimensional segment tree as a tree in a tree:
```go
inner := new(segtree.Tree)
inner.Push(1, 10, "hello, world")
inner.BuildTree()

outer := new(Tree)
outer.Push(0, 99, inner)
{'fraction_non_alphanumeric': 0.1372021521906226, 'fraction_numerical': 0.03689469638739431, 'mean_word_length': 4.561965811965812, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4053968', 'n_tokens_mistral': 917, 'n_tokens_neox': 837, 'n_words': 302}