SmallData

package module
v0.0.0-...-0575265 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2019 License: MIT Imports: 7 Imported by: 1

README

SmallData

A simple, easy to use and build (no 3rd party dependencies!) Key/Value hash list to faciliate an in memory database.

Getting Started

SmallData.NewTable(1024)

key   := "some key"
value := "some value"
err := htv.StoreString(key, value)
if err != nil {
    // handle err...
}

ret := htv.SearchString(key)
fmt.Println(ret)
// $> some value

The way collisions are handled is a set of semi-colon delimited values.

key := "some_key"
value01 := "some value"
value02 := "some other value"

err := htv.StoreString(key, value01)
if err != nil {
    // handle err ...
}
err := htv.StoreString(key, value02)
if err != nil {
    // handle err ...
}

ret := htv.SearchString(key)
fmt.Println(ret)
// $> some value;some other value

Example Programs

Example programs that show you how the library could be used.

cmd/cli: a command line interface

Installation
$ cd cmd/cli
$ go build
$ ./cli
Usage

exit: exits out of the cli.

help: prints this helpful message.

insert: inserts into the hash table

    Example: $> insert key_name value [value...]

search: searchs for a value in the hash table based on a key

    Example: $> search key

    Return : $> value...

search_key: searchs for a value in the hash table based on a key

    Example: $> search_key 42402122

    Return : $> value... 

remove: removes a key and its associated value from the hash table

    Example: $> remove key

dump : dumps to a config based file (default is dump.dat)

print : prints out the hash table and all it's values

    NOTE: 0's are null values in the hash table

stats : prints the max amount of entries and current amount of entries

byte_me: returns the go based array of bytes of a given string

hash_me: returns a hashed value based on the string given

Tests

The testing is currently only in a happy path state. These tests are meant for regression testing for a continous integreation tool. All the tests are located in SmallData_test.go.

To run all the tests:

go test -v 
TestCoverage

Test coverage as of now is 80.2% according to

go test -cover 

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

Documentation

Overview

SmallData is a key/value hash list implementation that can be written/read from disk

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BunkHashCode

func BunkHashCode(k int) int

func BunkHashString

func BunkHashString(s string) int

just a wrapper for testing some stuff

Types

type HashTable

type HashTable struct {
	Table []HashTableData

	CurrentEntries int
	MaxTableSize   int

	FileName string
}

HashTable is the data structure for the HashTable itself which holds the array of HashTableData, the current entry count, the max table size, and the dump file name

func NewTable

func NewTable(size int) *HashTable

NewTable returns a New HashTable that is the size of the given size * the size of a HashTable

func NewTableFromFile

func NewTableFromFile(fileName string, defaultSize int) *HashTable

NewTable from file returns a New Hash table based on a dump file given it will be the size of the file. If the file cannot be found a clean table will be produced with the default size given.

func (*HashTable) Dump

func (ht *HashTable) Dump()

Dump dumps the contents of the table into a file the name of the dump file is determined by the name given upon intialization of the hashtable

func (HashTable) Print

func (ht HashTable) Print()

func (*HashTable) Remove

func (ht *HashTable) Remove(k string) error

Remove removes a value from the hash table by nulling the value and assigning a 0 to the key

func (*HashTable) SearchForData

func (ht *HashTable) SearchForData(k int) *HashTableData

Search searchs for the HashTableData entry of the value of the given int key

func (*HashTable) SearchKey

func (ht *HashTable) SearchKey(k int) string

SearchString searchs for the string Value of the given string Hashed Key Int

func (*HashTable) SearchString

func (ht *HashTable) SearchString(k string) string

SearchString searchs for the string Value of the given string Key

func (HashTable) Stats

func (ht HashTable) Stats()

func (*HashTable) StoreBytes

func (ht *HashTable) StoreBytes(key []byte, value []byte) error

StoreBytes is the same as StoreString but use type []byte for the key and value

func (*HashTable) StoreBytesWithTimeStamp

func (ht *HashTable) StoreBytesWithTimeStamp(input []byte) (int, error)

StoreBytesWithTimeStamp will use time of storage to create a hash key and will store the given byte array it will then return the hashed integer value for searching later on

func (*HashTable) StoreString

func (ht *HashTable) StoreString(key string, value string) error

StoreString stores the a given value into the table index by a hash created by the given key

type HashTableData

type HashTableData struct {
	Key   int
	Value []byte
}

HashTableData is the data structure that holds the basic Key/Value information of every entry

Directories

Path Synopsis
cmd
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL