summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/toqueteos
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2020-02-11 11:34:17 +0200
committerGitHub <noreply@github.com>2020-02-11 11:34:17 +0200
commitad2642a8aac9facb217a8471df1d3e00f1214e92 (patch)
treeea198b2b3130d22bb60886b6ba0a1df352f160ff /vendor/github.com/toqueteos
parent37892be63580e40ced80e041ff2e7dabb2e80866 (diff)
downloadgitea-ad2642a8aac9facb217a8471df1d3e00f1214e92.tar.gz
gitea-ad2642a8aac9facb217a8471df1d3e00f1214e92.zip
Language statistics bar for repositories (#8037)
* Implementation for calculating language statistics Impement saving code language statistics to database Implement rendering langauge stats Add primary laguage to show in repository list Implement repository stats indexer queue Add indexer test Refactor to use queue module * Do not timeout for queues
Diffstat (limited to 'vendor/github.com/toqueteos')
-rw-r--r--vendor/github.com/toqueteos/trie/LICENSE.txt22
-rw-r--r--vendor/github.com/toqueteos/trie/README.md7
-rw-r--r--vendor/github.com/toqueteos/trie/go.mod1
-rw-r--r--vendor/github.com/toqueteos/trie/trie.go102
4 files changed, 132 insertions, 0 deletions
diff --git a/vendor/github.com/toqueteos/trie/LICENSE.txt b/vendor/github.com/toqueteos/trie/LICENSE.txt
new file mode 100644
index 0000000000..d04c50223b
--- /dev/null
+++ b/vendor/github.com/toqueteos/trie/LICENSE.txt
@@ -0,0 +1,22 @@
+Copyright (c) 2013 Caleb Spare
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/vendor/github.com/toqueteos/trie/README.md b/vendor/github.com/toqueteos/trie/README.md
new file mode 100644
index 0000000000..3372521de4
--- /dev/null
+++ b/vendor/github.com/toqueteos/trie/README.md
@@ -0,0 +1,7 @@
+# Trie
+
+[![GoDoc](http://godoc.org/github.com/toqueteos/trie?status.png)](http://godoc.org/github.com/toqueteos/trie)
+
+This is a fork of https://github.com/cespare/go-trie that adds the `PrefixIndex` method.
+
+It's required for https://github.com/toqueteos/substring.
diff --git a/vendor/github.com/toqueteos/trie/go.mod b/vendor/github.com/toqueteos/trie/go.mod
new file mode 100644
index 0000000000..24f2eb5fe7
--- /dev/null
+++ b/vendor/github.com/toqueteos/trie/go.mod
@@ -0,0 +1 @@
+module github.com/toqueteos/trie
diff --git a/vendor/github.com/toqueteos/trie/trie.go b/vendor/github.com/toqueteos/trie/trie.go
new file mode 100644
index 0000000000..4411f3e429
--- /dev/null
+++ b/vendor/github.com/toqueteos/trie/trie.go
@@ -0,0 +1,102 @@
+// Package trie is an implementation of a trie (prefix tree) data structure over byte slices. It provides a
+// small and simple API for usage as a set as well as a 'Node' API for walking the trie.
+package trie
+
+// A Trie is a a prefix tree.
+type Trie struct {
+ root *Node
+}
+
+// New construct a new, empty Trie ready for use.
+func New() *Trie {
+ return &Trie{
+ root: &Node{},
+ }
+}
+
+// Insert puts b into the Trie. It returns true if the element was not previously in t.
+func (t *Trie) Insert(b []byte) bool {
+ n := t.root
+ for _, c := range b {
+ next, ok := n.Walk(c)
+ if !ok {
+ next = &Node{}
+ n.branches[c] = next
+ n.hasChildren = true
+ }
+ n = next
+ }
+ if n.terminal {
+ return false
+ }
+ n.terminal = true
+ return true
+}
+
+// Contains checks t for membership of b.
+func (t *Trie) Contains(b []byte) bool {
+ n := t.root
+ for _, c := range b {
+ next, ok := n.Walk(c)
+ if !ok {
+ return false
+ }
+ n = next
+ }
+ return n.terminal
+}
+
+// PrefixIndex walks through `b` until a prefix is found (terminal node) or it is exhausted.
+func (t *Trie) PrefixIndex(b []byte) int {
+ var idx int
+ n := t.root
+ for _, c := range b {
+ next, ok := n.Walk(c)
+ if !ok {
+ return -1
+ }
+ if next.terminal {
+ return idx
+ }
+ n = next
+ idx++
+ }
+ if !n.terminal {
+ idx = -1
+ }
+ return idx
+}
+
+// Root returns the root node of a Trie. A valid Trie (i.e., constructed with New), always has a non-nil root
+// node.
+func (t *Trie) Root() *Node {
+ return t.root
+}
+
+// A Node represents a logical vertex in the trie structure.
+type Node struct {
+ branches [256]*Node
+ terminal bool
+ hasChildren bool
+}
+
+// Walk returns the node reached along edge c, if one exists. The ok value indicates whether such a node
+// exist.
+func (n *Node) Walk(c byte) (next *Node, ok bool) {
+ next = n.branches[int(c)]
+ return next, (next != nil)
+}
+
+// Terminal indicates whether n is terminal in the trie (that is, whether the path from the root to n
+// represents an element in the set). For instance, if the root node is terminal, then []byte{} is in the
+// trie.
+func (n *Node) Terminal() bool {
+ return n.terminal
+}
+
+// Leaf indicates whether n is a leaf node in the trie (that is, whether it has children). A leaf node must be
+// terminal (else it would not exist). Logically, if n is a leaf node then the []byte represented by the path
+// from the root to n is not a proper prefix of any element of the trie.
+func (n *Node) Leaf() bool {
+ return !n.hasChildren
+}