medley

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README

medley

medley does something good.

Build Status Dependency Updateer codecov.io Go Report Card Quality Gate Status Apache V2 License GitHub Release GoDoc

Setup

  1. Search and replace medley with your project name.
  2. Initialize go.mod file: go mod init github.com/xmidt-org/medley
  3. Add org teams to project (Settings > Manage Access):
    • xmidt-org/admins with Admin role
    • xmidt-org/server-writers with Write role
  4. Manually create the first release. After v0.0.1 exists, other releases will be made by automation after the CHANGELOG is updated to reflect a new version header and nothing under the Unreleased header.
  5. For libraries:
    1. Add org workflows in dir .github/workflows: push, tag, and release. This can be done by going to the Actions tab for the repo on the github site.
    2. Remove the following files/dirs: .dockerignore, Dockerfile, Makefile, rpkg.macros, medley.yaml, deploy/, and conf/.

Summary

Medley is a consistent hash package that also exposes a simple API for creating additional hash strategies.

Table of Contents

Code of Conduct

This project and everyone participating in it are governed by the XMiDT Code Of Conduct. By participating, you agree to this Code.

Contributing

Refer to CONTRIBUTING.md.

Documentation

Overview

Package medley implements distributed hashing aimed at microservices. Currently, only consistent hashing is implemented.

Index

Constants

View Source
const (
	// AlgorithmFNV is the configuration value for an fnv.New64a algorithm
	AlgorithmFNV = "fnv"

	// AlgorithmMurmur3 is the configuration value for a murmur3.New64 algorithm
	AlgorithmMurmur3 = "murmur3"
)

Variables

This section is empty.

Functions

func ComputeHash

func ComputeHash(k Key, alg Algorithm) uint64

ComputeHash is a convenience for computing a single key's hash value using an algorithm. In general, the hash object returned from an Algorithm should be reset and reused when computing many hash values. This function is provided as a utility for test code and a convenience for tools that can query a hash.

Types

type Algorithm

type Algorithm func() hash.Hash64

Algorithm is a constructor for a 64-bit hash object. The various NewXXX function in the stdlib hash subpackages are of this type.

func DefaultAlgorithm

func DefaultAlgorithm() Algorithm

DefaultAlgorithm returns the Algorithm to be used when none is supplied or configured. Currently, this package defaults to github.com/spaolacci/murmur3.

func FindAlgorithm

func FindAlgorithm(name string, extensions map[string]Algorithm) (Algorithm, error)

FindAlgorithm accepts a configured name and attempts to locate the appropriate Algorithm. The set of built-in algorithms is consulted first, followed by the extensions (if supplied). The set of extensions can be nil. If name is empty, DefaultAlgorithm() is returned.

This function will return an error of type *UnknownAlgorithmError if no such algorithm was found.

func GetAlgorithm

func GetAlgorithm(name string) (Algorithm, error)

GetAlgorithm accepts a configured name and attempts to locate the built-in algorithm associated with that name. If name is empty, DefaultAlgorithm() is returned.

This function will return an error of type *UnknownAlgorithmError if no such algorithm was found.

type Bytes

type Bytes []byte

Bytes is a Key which is a slice of bytes

func (Bytes) WriteTo

func (b Bytes) WriteTo(w io.Writer) (int64, error)

WriteTo writes this Bytes key's contents to the given writer

type Key

type Key interface {
	io.WriterTo
}

Key defines the behavior of hash keys. All hash keys can write their own hashable bytes to an output sink.

type Node

type Node string

Node is a string type that is assigned hash values in a ring. A node can be any string, but is most often a URL or host name.

var NilNode Node = Node("")

NilNode is the canonicalized nil value for nodes

func (Node) WriteTo

func (n Node) WriteTo(w io.Writer) (int64, error)

WriteTo fulfills the io.WriterTo interface and allows nodes to write their own hash bytes to a writer.

type NodeSet

type NodeSet map[Node]bool

NodeSet is a set of nodes. The zero value of this type is ready to use.

The typical use case for a NodeSet is to track which nodes are part of a hash. Without a set, the hash would likely need to do binary or even linear searches to determine if a node was already hashed.

func NewNodeSet

func NewNodeSet(nodes ...Node) NodeSet

NewNodeSet constructs a NodeSet from a slice of nodes

func (*NodeSet) Add

func (ns *NodeSet) Add(n Node) (added bool)

Add inserts the given node into this set. This set is initialized as needed. This method returns true to indicate that the node was added, false to indicate that the node was already present.

func (*NodeSet) AddAll

func (ns *NodeSet) AddAll(nodes ...Node) (count int)

AddAll adds each of a sequence of nodes. Any nodes already in this set are not modified. This method returns the count of nodes actually added.

As with Add, this set is initialized as needed.

func (NodeSet) Filter

func (ns NodeSet) Filter(nodes []Node) (in, notIn []Node)

Filter examines each node in a slice to determine if it is present in this set. The slice is rearranged in-place so that nodes that are in this set are contiguous in the first portion of the slice, while all the nodes not in this set follow. The two slices that are returned point into the given slice and contain the nodes in and not in this set, respectively.

func (NodeSet) Has

func (ns NodeSet) Has(n Node) bool

Has tests if the given node is present in this set

func (NodeSet) Len

func (ns NodeSet) Len() int

Len returns the count of nodes in this set

func (*NodeSet) Remove

func (ns *NodeSet) Remove(n Node) (removed bool)

Remove deletes a node from this set. This method returns true if the node was deleted, false to indicate the node did not exist in this set.

func (*NodeSet) RemoveAll

func (ns *NodeSet) RemoveAll(nodes ...Node) (count int)

RemoveAll deletes each of a sequence of nodes. Any node not present in this set is ignored. This method returns the count of nodes actually deleted.

type String

type String string

String is a Key which is a golang string

func (String) WriteTo

func (s String) WriteTo(w io.Writer) (int64, error)

WriteTo writes this string's contents to the given writer. io.WriteString is used to optimize string writing where possible.

type UnknownAlgorithmError

type UnknownAlgorithmError struct {
	// Name is the name which is unrecognized.  This will never be blank,
	// as a blank name is interpreted as AlgorithmDefault.
	Name string
}

UnknownAlgorithmError indicates that no algorithm could be created using the given Name

func (*UnknownAlgorithmError) Error

func (e *UnknownAlgorithmError) Error() string

Error fulfills the error interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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