GithubHelp home page GithubHelp logo

timtadh / data-structures Goto Github PK

View Code? Open in Web Editor NEW
415.0 24.0 82.0 1.22 MB

Go datastructures.

Home Page: http://hackthology.com/data-structures/

License: Other

Go 100.00%
data-structures avl-tree avl immutable btree hashtable hash-tables linear-hash-table trie ternary-search-trie

data-structures's People

Contributors

jrisc avatar timtadh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

data-structures's Issues

Error stack performance problem

Hi, I used the hashtable from your library. When I use the hashtable and often got hit miss, the library generates a lot of stack. It turns out to be an expensive operation.
Could we remove it and just use error wrapping instead?
image

Please provide example code.

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.

get panic when iterator an empty trie

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

Ternary search tree panic on prefix search

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.

Tests break under Windows because of /dev/urandom

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).

get non-existence key from hash would cause panic

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))
		}
	}
}

Use float64 as key in bptree

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.