Socket
Book a DemoInstallSign in
Socket

github.com/kchristidis/cmap

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/kchristidis/cmap

Source
Go
Version
v0.1.0
Version published
Created
Source

cmap

GoDoc Build Status

A thread-safe capacity-constrained hash table that evicts key/value pairs according to the LRU (least recently used) policy. It is technically a thin wrapper around Go's built-in map type.

Usage

package main

import (
    cmap "github.com/kchristidis/cmap
)

func main() {
    cm, err := cmap.New(2) // will hold up to 2 key/value pairs
    if err != nil {
        log.Fatal(err)
    }

    cm.Put("fooKey", "fooVal")
    v, ok := cm.Get("fooKey") // retrieve the value
    fmt.Println(ok)
    fmt.Println(v)

    cm.Put("barKey", "barVal") // retrieve value as above
    cm.Put("bazKey", "bazVal") // at this point "fooKey" is evicted

    _, ok = cm.Get("fooKey")
    fmt.Println(ok) // expected output: false
}

You may also want to consult the package documentation in GoDoc.

Contributing

Contributions are welcome. Fork this library and submit a pull request.

FAQs

Package last updated on 01 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts