Comparing version 1.0.0 to 1.0.1
@@ -1,1 +0,5 @@ | ||
export { default } from "./lru"; | ||
export default function createLRUCache<K, V>(capacity: number): { | ||
[key: string]: V; | ||
} | { | ||
[key: number]: V; | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = void 0; | ||
var lru_1 = require("./lru"); | ||
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return lru_1.default; } }); | ||
const lru_1 = require("./lru"); | ||
function createLRUCache(capacity) { | ||
const lru = new lru_1.default(capacity); | ||
const cache = lru.nodes; | ||
const handler = { | ||
get(_, prop) { | ||
return lru.get(prop); | ||
}, | ||
set(_, prop, value) { | ||
lru.set(prop, value); | ||
return true; | ||
}, | ||
}; | ||
return new Proxy(cache, handler); | ||
} | ||
exports.default = createLRUCache; |
@@ -1,9 +0,3 @@ | ||
export declare class Node<K, V> { | ||
key: any; | ||
value: any; | ||
prev: Node<K, V>; | ||
next: Node<K, V>; | ||
constructor(key?: any, value?: any, prev?: Node<K, V>, next?: Node<K, V>); | ||
} | ||
export declare class LRU<K, V> { | ||
import Node from "./node"; | ||
export default class LRU<K, V> { | ||
head: Node<K, V>; | ||
@@ -25,6 +19,1 @@ tail: Node<K, V>; | ||
} | ||
export default function createLRUCache<K, V>(capacity: number): { | ||
[key: string]: V; | ||
} | { | ||
[key: number]: V; | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LRU = exports.Node = void 0; | ||
class Node { | ||
constructor(key, value, prev, next) { | ||
this.key = key; | ||
this.value = value; | ||
this.prev = prev; | ||
this.next = next; | ||
} | ||
} | ||
exports.Node = Node; | ||
const node_1 = require("./node"); | ||
class LRU { | ||
constructor(capacity) { | ||
this.head = new Node(); | ||
this.tail = new Node(); | ||
this.head = new node_1.default(); | ||
this.tail = new node_1.default(); | ||
this.head.next = this.tail; | ||
@@ -22,5 +13,2 @@ this.tail.prev = this.head; | ||
this.capacity = capacity; | ||
if (capacity <= 0) { | ||
console.error("LRU capacity must be gratter than 0"); | ||
} | ||
} | ||
@@ -43,3 +31,3 @@ peek(key) { | ||
} | ||
const newNode = new Node(key, value); | ||
const newNode = new node_1.default(key, value); | ||
const next = this.head.next; | ||
@@ -86,17 +74,2 @@ this.head.next = newNode; | ||
} | ||
exports.LRU = LRU; | ||
function createLRUCache(capacity) { | ||
const lru = new LRU(capacity); | ||
const cache = lru.nodes; | ||
const handler = { | ||
get: function (_, prop) { | ||
return lru.get(prop); | ||
}, | ||
set: function (_, prop, value) { | ||
lru.set(prop, value); | ||
return true; | ||
}, | ||
}; | ||
return new Proxy(cache, handler); | ||
} | ||
exports.default = createLRUCache; | ||
exports.default = LRU; |
{ | ||
"name": "lru-object", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Javascript object with basic LRU functionalities", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13
6919
154