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

@graphile/lru

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphile/lru - npm Package Compare versions

Comparing version 5.0.0-alpha.1 to 5.0.0-alpha.2

12

CHANGELOG.md
# @graphile/lru
## 5.0.0-alpha.2
### Patch Changes
- [`98ae00f59`](https://github.com/benjie/postgraphile-private/commit/98ae00f59a8ab3edc5718ad8437a0dab734a7d69)
Thanks [@benjie](https://github.com/benjie)! - Performance overhaul and faster
access for unsaturated LRUs.
- [`7f857950a`](https://github.com/benjie/postgraphile-private/commit/7f857950a7e4ec763c936eb6bd1fb77824041d71)
Thanks [@benjie](https://github.com/benjie)! - Upgrade to the latest
TypeScript/tslib
## 5.0.0-alpha.1

@@ -4,0 +16,0 @@

4

dist/index.d.ts

@@ -20,2 +20,4 @@ export interface LRUOptions<KeyType, ValueType> {

private d;
/** saturated (length === max length) */
private s;
constructor({ maxLength, dispose }: LRUOptions<KeyType, ValueType>);

@@ -25,4 +27,2 @@ reset(): void;

set(key: KeyType, value: ValueType): void;
/** hoist (aka "raise") */
private r;
/** add */

@@ -29,0 +29,0 @@ private a;

@@ -26,2 +26,6 @@ "use strict";

exports.LRU = void 0;
/** An optimized get to use before the LRU saturates */
function quickGet(key) {
return this.c.get(key)?.v;
}
/**

@@ -31,13 +35,2 @@ * An tiny LRU cache with maximum count, identical weighting and no expiration.

class LRU {
length;
/** max length */
m;
/** head */
h;
/** tail */
t;
/** cache */
c;
/** dispose */
d;
constructor({ maxLength, dispose }) {

@@ -56,2 +49,4 @@ if (maxLength < 2) {

this.d = dispose || null;
this.s = false;
this.get = quickGet;
this.reset();

@@ -65,3 +60,3 @@ }

this.length = 0;
if (this.d) {
if (this.d !== null) {
for (const hit of values) {

@@ -74,11 +69,31 @@ this.d(hit.k, hit.v);

const hit = this.c.get(key);
if (hit) {
this.r(hit);
return hit.v;
if (hit === undefined) {
return undefined;
}
return undefined;
// HOIST
if (this.h === null) {
this.h = this.t = hit;
}
else if (hit !== this.h) {
// Remove newHead from old position
hit.p.n = hit.n;
if (hit.n !== null) {
hit.n.p = hit.p;
}
else {
// It was the t, now hit.prev is the t
this.t = hit.p;
}
// Add hit at top
hit.n = this.h;
this.h.p = hit;
this.h = hit;
hit.p = null;
}
// RETURN
return hit.v;
}
set(key, value) {
const hit = this.c.get(key);
if (hit) {
if (hit !== undefined) {
hit.v = value;

@@ -97,29 +112,5 @@ }

}
/** hoist (aka "raise") */
r(newHead) {
if (newHead === this.h) {
return;
}
if (!this.h) {
this.h = this.t = newHead;
return;
}
// Remove newHead from old position
newHead.p.n = newHead.n;
if (newHead.n) {
newHead.n.p = newHead.p;
}
else {
// It was the t, now newHead.prev is the t
this.t = newHead.p;
}
// Add newHead at top
newHead.n = this.h;
this.h.p = newHead;
this.h = newHead;
newHead.p = null;
}
/** add */
a(newHead) {
if (!this.h) {
if (this.h === null) {
this.h = this.t = newHead;

@@ -132,3 +123,3 @@ this.length = 1;

this.h = newHead;
if (this.length === this.m) {
if (this.s) {
// Remove the t

@@ -139,3 +130,3 @@ const oldTail = this.t;

this.t.n = null;
if (this.d) {
if (this.d !== null) {
this.d(oldTail.k, oldTail.v);

@@ -149,2 +140,6 @@ }

this.length++;
if (this.length === this.m) {
this.s = true;
this.get = LRU.prototype.get;
}
}

@@ -151,0 +146,0 @@ }

{
"name": "@graphile/lru",
"version": "5.0.0-alpha.1",
"version": "5.0.0-alpha.2",
"description": "Extremely simple zero-dependencies ES6 LRU (you probably want lru-cache instead)",

@@ -33,3 +33,3 @@ "main": "dist/index.js",

"dependencies": {
"tslib": "^2.4.0"
"tslib": "^2.5.0"
},

@@ -41,4 +41,4 @@ "devDependencies": {

"ts-node": "^10.9.1",
"typescript": "^5.0.0-beta"
"typescript": "^5.0.4"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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