gomap

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2023 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-map

Go's 1.19 hashmap implementation using pure Go with generics.

About

This is Go's 1.19 map implementation written with pure Go. Using this repo you can learn how maps work in Go internally and undestand the main concept of a hashmap in general. This repo uses algorithms from an actual map implementation under the Go's hood, except some things due to better undestanding.

This code was written additionaly to my article on Habr, where I've desribed maps internals - what is a hashmap, main terms, concepts, difference with Python and Java.

Here you can find some kind of auto-generated English translation.

You can also use this repo as a start point to improve/change a base implementation that we have in Go 1.19.

Contributions

Any contributions are welcome. Don't hesitate creating PRs to improve similarity to a base implementation, to fix bugs, typos, redability etc.

Articles\videos which will help you to delve into a hashmap:

Go:
GopherCon 2016: Keith Randall - Inside the Map Implementation
How the Go runtime implements maps efficiently (without generics)
Hacking Go's Runtime with Generics

Python:
Raymond Hettinger Modern Python Dictionaries A confluence of a dozen great ideas PyCon 2017
Raymond Hettinger.More compact dictionaries with faster iteration

Java:
The Java HashMap Under the Hood
Liner probing lecture. cs166 stanford
An Analysis of Hash Map Implementations in Popular Languages

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hashmap

type Hashmap[K comparable, V any] interface {
	// gets the value for the given key.
	// returns zero value for <V> if there is no value for the given key
	Get(key K) V
	// gets the value for the given key and the flag indicating whether the value exists
	// returns zero value for <V> and false if there is no value for the given key
	Get2(key K) (V, bool)
	// puts value into the map
	Put(key K, value V)
	// deletes an element from the map
	Delete(key K)
	// iterates through the map and calls the given func for each key, value.
	// if the given func returns false, loop breaks.
	Range(f func(k K, v V) bool)
	// returns the length of the map
	Len() int
	String() string
}

func New

func New[K comparable, V any](size int) Hashmap[K, V]

New - creates a new map for <size> elements

Jump to

Keyboard shortcuts

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