GithubHelp home page GithubHelp logo

isabella232 / lrucache.nim Goto Github PK

View Code? Open in Web Editor NEW

This project forked from status-im/lrucache.nim

0.0 0.0 0.0 67 KB

LRU cache in pure nim

Home Page: https://jackhftang.github.io/lrucache.nim/

Nim 100.00%

lrucache.nim's Introduction

LRU cache

The standard implemenation of LRU cache (hash table + doubly-linked list). All operations are in time complexity of O(1). This implementation is not thread-safe.

Installation

$ nimble install lrucache

API

See api docs

Usage

# create a new LRU cache with initial capacity of 1 items
let cache = newLRUCache[int, string](1) 

cache[1] = "a"
cache[2] = "b"

# key 1 is not in cache, because key 1 is eldest and capacity is only 1
assert: 1 notin cache 
assert: 2 in cache

# increase capacity and add key 1 
cache.capacity = 2 
cache[1] = "a"
assert: 1 in cache
assert: 2 in cache

# update recentness of key 2 and add key 3, then key 1 will be discarded.
echo cache[2]
cache[3] = "c"
assert: 1 notin cache
assert: 2 in cache
assert: 3 in cache

lrucache devs - create a release

Put a personal access token named GITHUB_TOKEN in your environment with repo access. You can then release interactively using nimble release. This will provide options for creating a release commit, a tag, and a github release, and handle the push for you. You can also achieve this non-interactively with nimble release_patch, nimble release_minor, or nimble release_major. NOTE: if a GITHUB_TOKEN is not in your environment, but you have a git user configured for the current working directory with enough permissions for the repository, then likely the commit and tag push will work, but the release creation will fail.

# Launch interactive release process
nimble release
# Launch non-interactive release process for patch release
nimble release_patch
# Launch non-interactive release process for minor release
nimble release_minor
# Launch non-interactive release process for major release
nimble release_major

lrucache.nim's People

Contributors

demotomohiro avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.