timtadh / data-structures Goto Github PK
View Code? Open in Web Editor NEWGo datastructures.
Home Page: http://hackthology.com/data-structures/
License: Other
Go datastructures.
Home Page: http://hackthology.com/data-structures/
License: Other
Your readme states that you provide "generic types to allow the user to swap out various data structures transparently. The interfaces provide operation for adding, removing, retrieving objects from collections as well as iterating over the collection using functional iterators."
How does this work? For example:
var myKey int16 = 1
table := NewHashTable(10)
var key types.Int16
// XXX: key = myKey
var value interface{} = myData
var err error
value, err = table.Put(key, value)
I don't understand how to assign myKey to the types.Int16 key.
Thank you.
Hi:
this is the case
package main
import (
"github.com/timtadh/data-structures/trie"
)
func main() {
t := trie.New()
for _, _, next := t.Iterate()(); next != nil; _, _, next = next() {
}
}
golang version: go version go1.11.4 linux/amd64
when i'm using go run, it occurs
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x48ac3b]
goroutine 1 [running]:
github.com/timtadh/data-structures/trie.(*TST).Iterate.func1(0xc000067788, 0xc000090020, 0x0, 0x0, 0x0)
/home/tcp9/go/src/github.com/timtadh/data-structures/trie/tst.go:215 +0x3b
main.main()
/home/tcp9/go/src/test/test/main.go:9 +0x62
https://github.com/timtadh/data-structures/blob/master/trie/tst.go#L173
This line panics if the prefix being searched for is longer than the capacity of the key being checked, e.g. this panics:
tst := trie.New()
tst.Put([]byte("abc"), nil)
_, _, _ = tst.PrefixFind([]byte("abcxxxxxxxxxxxxxxxxxxxx"))()
panic: runtime error: slice bounds out of range [:23] with capacity 8
...
github.com/timtadh/data-structures/trie.(*TST).PrefixFind(0xc000092760?, {0xc000092749, 0x17, 0x3?})
/go/pkg/mod/github.com/timtadh/[email protected]/trie/tst.go:173 +0x297
...
Since the slice operation succeeds if the index is larger than the length but smaller than the capacity this doesn't always occur for prefixes that are slightly longer than the found leaf node.
Several places in your code, you open /dev/urandom directly, and use that to feed into math/rand.Seed(). This breaks Windows tests, as /dev/urandom is Linux only.
Consider switching to crypto/rand.Read() as seed source instead, or just using current timestamp to seed with, that's universal.
Additionally in sortedset.go (init) you should not apply seeding. It's not really your library's responsibility to do so. For testing, modules, yes, but otherwise actually it's the programmers responsibility (perhaps they want to keep it unseeded for reproducable testing).
package main
import (
hashtable "github.com/timtadh/data-structures/hashtable"
"fmt"
types "github.com/timtadh/data-structures/types"
)
func main() {
hash := hashtable.NewHashTable(10)
hash.Put(types.String(1),"a")
v , err :=hash.Get(types.String(1))
if err != nil{
fmt.Println(err.Error())
}else{
if v != nil{
fmt.Println(v.(string))
}
}
}
As it currently stands. It seems I can only use "types.Int" as keys in the bptree is there a way we can use float64 instead?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.