countset

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 2 Imported by: 0

README

countset — efficient binary encoding of generic countable set (map[K]int).

Documentation

Overview

Example (CustomType)
package main

import (
	"fmt"
	"maps"

	"github.com/ndx-technologies/countset"
)

func main() {
	type ID uint64
	id := ID(1234)

	m := map[ID]int{
		id: -11,
	}

	b, _ := countset.MarshalBinary(m)
	m2, _ := countset.UnmarshalBinary[ID, int](b)

	fmt.Println(maps.Equal(m, m2), m[id])
}
Output:

true -11
Example (Uint64)
package main

import (
	"fmt"
	"maps"

	"github.com/ndx-technologies/countset"
)

func main() {
	m := map[uint64]int{
		1234: -11,
	}

	b, _ := countset.MarshalBinary(m)
	m2, _ := countset.UnmarshalBinary[uint64, int](b)

	fmt.Println(maps.Equal(m, m2), m[1234])
}
Output:

true -11

Index

Examples

Constants

This section is empty.

Variables

View Source
var ByteOrder = binary.LittleEndian

Functions

func AppendBinary

func AppendBinary[K ~uint64, V ~int](b []byte, mp map[K]V) ([]byte, error)

func MarshalBinary

func MarshalBinary[K ~uint64, V ~int](mp map[K]V) ([]byte, error)

func UnmarshalBinary

func UnmarshalBinary[K ~uint64, V ~int](data []byte) (map[K]V, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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