hashmap

package
v6.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2019 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Copyright 2018 the u-root Authors. All rights reserved Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. Package hashmap implements persistent hashmap.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasKey

func HasKey(m Map, k interface{}) bool

HasKey reports whether a Map has the given key.

Types

type Equal

type Equal func(k1, k2 interface{}) bool

Equal is the type of a function that reports whether two keys are equal.

type Hash

type Hash func(k interface{}) uint32

Hash is the type of a function that returns the hash code of a key.

type Iterator

type Iterator interface {
	// Elem returns the current key-value pair.
	Elem() (interface{}, interface{})
	// HasElem returns whether the iterator is pointing to an element.
	HasElem() bool
	// Next moves the iterator to the next position.
	Next()
}

Iterator is an iterator over map elements. It can be used like this:

for it := m.Iterator(); it.HasElem(); it.Next() {
    key, value := it.Elem()
    // do something with elem...
}

type Map

type Map interface {
	Len() int
	// Index returns whether there is a value associated with the given key, and
	// that value or nil.
	Index(k interface{}) (interface{}, bool)
	// Assoc returns an almost identical map, with the given key associated with
	// the given value.
	Assoc(k, v interface{}) Map
	// Dissoc returns an almost identical map, with the given key associated
	// with no value.
	Dissoc(k interface{}) Map
	// Iterator returns an iterator over the map.
	Iterator() Iterator
}

Map is a persistent associative data structure mapping keys to values. It is immutable, and supports near-O(1) operations to create modified version of the map that shares the underlying data structure. Because it is immutable, all of its methods are safe for concurrent use.

func New

func New(e Equal, h Hash) Map

New takes an equality function and a hash function, and returns an empty Map.

Jump to

Keyboard shortcuts

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