kkmap

package
v0.0.0-...-110d06e Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 2 Imported by: 0

README

kkmap

A map type with two keys

Install

go get github.com/hollson/kkmap

Usage

package main

import (
    "fmt"
    "github.com/hollson/kkmap"
)

// define a kkmap object
type TcpPacket struct {
    UUID      string
    RemoteUrl string
    Name      string
}

func (t *TcpPacket) String() string {
    return fmt.Sprintf("%+v", *t)
}

func (t *TcpPacket) Key1() interface{} {
    return t.UUID
}

func (t *TcpPacket) Key2() interface{} {
    return t.RemoteUrl
}

func main() {
    // create a kkmap
    kk := kkmap.NewMap()
    kk.Set(&TcpPacket{
        UUID:      "1001",
        RemoteUrl: "127.0.0.1:8801",
        Name:      "tom",
    })

    kk.Set(&TcpPacket{
        UUID:      "1002",
        RemoteUrl: "127.0.0.1:8802",
        Name:      "jack",
    })

    kk.Set(&TcpPacket{
        UUID:      "1003",
        RemoteUrl: "127.0.0.1:8803",
        Name:      "lily",
    })

    kk.Set(&TcpPacket{
        UUID:      "1004",
        RemoteUrl: "127.0.0.1:8804",
        Name:      "lucy",
    })

    fmt.Println(kk.GetByKey2("127.0.0.1:8804"))
    fmt.Println(kk.GetByKey1("1001").(*TcpPacket).String())
    fmt.Println(kk.Length())

    kk.Delete(&TcpPacket{
        UUID:      "1001",
        RemoteUrl: "127.0.0.1:8801",
        Name:      "",
    })

    kk.RangeByKey1(func(k kkmap.KKobject) {
        fmt.Println(k.(*TcpPacket).UUID)
    })
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KKobject

type KKobject interface {
	Key1() interface{}
	Key2() interface{}
	fmt.Stringer
}

Object with two identity identifiers

type Map

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

map with double key

e.g. TcpPacket(uuid,remoteRul)

func NewMap

func NewMap() *Map

func (*Map) Check

func (k *Map) Check() bool

Check that the length of key1 and key1 are equal

func (*Map) Delete

func (k *Map) Delete(kk KKobject)

delete element of kkmap

func (*Map) DeleteByKey1

func (k *Map) DeleteByKey1(k1 interface{})

delete element of kkmap by key1

func (*Map) DeleteByKey2

func (k *Map) DeleteByKey2(k2 interface{})

delete element of kkmap by key2

func (*Map) GetByKey1

func (k *Map) GetByKey1(k1 interface{}) KKobject

get value by key1

func (*Map) GetByKey2

func (k *Map) GetByKey2(k2 interface{}) KKobject

get value by key2

func (*Map) Length

func (k *Map) Length() (k1len, k2len int)

get length of kkmap

func (*Map) RangeByKey1

func (k *Map) RangeByKey1(f func(KKobject))

range kkmap by key1

func (*Map) RangeByKey2

func (k *Map) RangeByKey2(f func(KKobject))

range kkmap by key1

func (*Map) Set

func (k *Map) Set(kk KKobject)

add or modify value of kkmap

func (*Map) String

func (k *Map) String() string

Jump to

Keyboard shortcuts

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