Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cache-mapset

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-mapset

Maps and Sets with cache replacement policies, TC39 proposal-policy-map-set implementation

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

cache-mapset

deno land deno doc GitHub release (latest by date) codecov License

test NPM standard-readme compliant semantic-release: angular

Maps and Sets with cache replacement policies, TC39 proposal-policy-map-set implementation. This can be used as a cache for TC39 proposal-function-memo and its implementation.

Usage

All Map-like constructors specify capacity.

When the limit is reached, the cache is adjusted according to the cache replacement policy.

import { LRUMap } from "https://deno.land/x/cache_mapset@$VERSION/mod.ts";
import { assert, assertEquals } from "https://deno.land/std/testing/asserts.ts";

declare const capacity: 2;

const map = new LRUMap<number, string>(capacity);

map.set(200, "Ok");
map.set(201, "Created");

assertEquals(map.size, 2);

map.set(202, "Accepted");

assertEquals(map.size, 2);
assert(map.has(201));
assert(map.has(202));

It provides a Map-like constructor with the following cache-replacement-policy:

Set like

SetLike is a set-like constructor, with the same cache-replacement-policy.

LFUSet preferentially removes item with fewer references (by has or add).

import { LFUSet } from "https://deno.land/x/cache_mapset@$VERSION/mod.ts";
import { assert, assertEquals } from "https://deno.land/std/testing/asserts.ts";

declare const capacity: 2;

const set = new LFUSet<number>(capacity);

set.add(200);
set.add(201);

assertEquals(set.size, 2);
assert(set.has(200));

set.add(202);

assert(set.has(200));
assert(set.has(202));

Initial value

Accepts an initial value, like Map or Set. If overcapacity occurs, the cache is adjusted according to the policy.

import { FIFOSet } from "https://deno.land/x/cache_mapset@$VERSION/mod.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

const set = new FIFOSet<number>(3, [0, 1, 2, 3, 4, 5]);
assertEquals(set.size, 3);

Errors

All constructors specify a capacity as their first argument.

If it is a negative number, an error is thrown.

import { FIFOMap } from "https://deno.land/x/cache_mapset@$VERSION/mod.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";

assertThrows(() => new FIFOMap(-1));

Difference from Map and Set

MapLike and SetLike are not Iterable.

The following members are not implemented.

  • Symbol.iterator
  • forEach
  • entries
  • keys
  • values

Currently, these are outside the scope of the specification. For more information, check Data iteration and order.

API

See deno doc for all APIs.

Contributing

See CONTRIBUTING.md

License

MIT © 2023 Tomoki Miyauchi

Keywords

FAQs

Package last updated on 18 Jun 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc