chd

package
v0.0.0-...-27647ab Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Copyright (c) 2014, Alec Thomas All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of SwapOff.org nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Package mph is a Go implementation of the compress, hash and displace (CHD) minimal perfect hash algorithm.

See http://cmph.sourceforge.net/papers/esa09.pdf for details.

To create and serialize a hash table:

b := mph.Builder()
for k, v := range data {
	b.Add(k, v)
}
h, _ := b.Build()
w, _ := os.Create("data.idx")
b, _ := h.Write(w)

To read from the hash table:

r, _ := os.Open("data.idx")
h, _ := h.Read(r)

v := h.Get([]byte("some key"))
if v == nil {
    // Key not found
}

MMAP is also indirectly supported, by deserializing from a byte slice and slicing the keys and values.

See https://github.com/alecthomas/mph for source.

Copyright (c) 2014, Alec Thomas All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of SwapOff.org nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chd

type Chd struct {
	// contains filtered or unexported fields
}

CHD hash table lookup.

func (*Chd) Get

func (c *Chd) Get(key []byte) []byte

Get an entry from the hash table.

func (*Chd) Iterate

func (c *Chd) Iterate() *ChdIterator

Iterate over entries in the hash table.

func (*Chd) Len

func (c *Chd) Len() int

func (*Chd) Write

func (c *Chd) Write(w io.Writer) error

Serialize the CHD. The serialized form is conducive to mmapped access. See the Mmap function for details.

type ChdBuilder

type ChdBuilder struct {
	// contains filtered or unexported fields
}

Build a new CDH MPH.

func NewChdBuilder

func NewChdBuilder() *ChdBuilder

Create a new Chd hash table builder.

func (*ChdBuilder) Add

func (b *ChdBuilder) Add(key []byte, value []byte)

Add a key and value to the hash table.

func (*ChdBuilder) Build

func (b *ChdBuilder) Build() (*Chd, error)

type ChdIterator

type ChdIterator struct {
	// contains filtered or unexported fields
}

func (*ChdIterator) Get

func (c *ChdIterator) Get() (key []byte, value []byte)

func (*ChdIterator) Next

func (c *ChdIterator) Next() *ChdIterator

Jump to

Keyboard shortcuts

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