-
-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revamp Build Infra for tiny-lru #27
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d35c2cb
remove extraneous files from lib
osdevisnot 7ae2bf7
remove slash stars form ignore files
osdevisnot ca96e77
remove npmignore, see 'files' in package.json for whitelist
osdevisnot 50f969a
ignore outout of npm pack
osdevisnot 6df99b8
add minimal tsconfig needed for tslib-cli
osdevisnot fc614a3
start using new build tool
osdevisnot 32da32a
add default export from outro to main file
osdevisnot bd366fc
remove special webapck usage instructions as it just works
osdevisnot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules/* | ||
.idea/* | ||
node_modules | ||
.idea | ||
*.tgz | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
'use strict'; | ||
|
||
class LRU { | ||
constructor (max = 0, ttl = 0) { | ||
this.first = null; | ||
this.items = {}; | ||
this.last = null; | ||
this.max = max; | ||
this.size = 0; | ||
this.ttl = ttl; | ||
} | ||
|
||
has (key) { | ||
return key in this.items; | ||
} | ||
|
||
clear () { | ||
this.first = null; | ||
this.items = {}; | ||
this.last = null; | ||
this.size = 0; | ||
|
||
return this; | ||
} | ||
|
||
delete (key) { | ||
if (this.has(key)) { | ||
const item = this.items[key]; | ||
|
||
delete this.items[key]; | ||
this.size--; | ||
|
||
if (item.prev !== null) { | ||
item.prev.next = item.next; | ||
} | ||
|
||
if (item.next !== null) { | ||
item.next.prev = item.prev; | ||
} | ||
|
||
if (this.first === item) { | ||
this.first = item.next; | ||
} | ||
|
||
if (this.last === item) { | ||
this.last = item.prev; | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
|
||
evict () { | ||
const item = this.first; | ||
|
||
delete this.items[item.key]; | ||
this.first = item.next; | ||
this.first.prev = null; | ||
this.size--; | ||
|
||
return this; | ||
} | ||
|
||
get (key) { | ||
let result; | ||
|
||
if (this.has(key)) { | ||
const item = this.items[key]; | ||
|
||
if (this.ttl > 0 && item.expiry <= new Date().getTime()) { | ||
this.delete(key); | ||
} else { | ||
result = item.value; | ||
this.set(key, result, true); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
keys () { | ||
return Object.keys(this.items); | ||
} | ||
|
||
set (key, value, bypass = false) { | ||
let item; | ||
|
||
if (bypass || this.has(key)) { | ||
item = this.items[key]; | ||
item.value = value; | ||
|
||
if (this.last !== item) { | ||
const last = this.last, | ||
next = item.next, | ||
prev = item.prev; | ||
|
||
if (this.first === item) { | ||
this.first = item.next; | ||
} | ||
|
||
item.next = null; | ||
item.prev = this.last; | ||
last.next = item; | ||
|
||
if (prev !== null) { | ||
prev.next = next; | ||
} | ||
|
||
if (next !== null) { | ||
next.prev = prev; | ||
} | ||
} | ||
} else { | ||
if (this.max > 0 && this.size === this.max) { | ||
this.evict(); | ||
} | ||
|
||
item = this.items[key] = { | ||
expiry: this.ttl > 0 ? new Date().getTime() + this.ttl : this.ttl, | ||
key: key, | ||
prev: this.last, | ||
next: null, | ||
value | ||
}; | ||
|
||
if (++this.size === 1) { | ||
this.first = item; | ||
} else { | ||
this.last.next = item; | ||
} | ||
} | ||
|
||
this.last = item; | ||
|
||
return this; | ||
} | ||
} | ||
|
||
function factory (max = 1000, ttl = 0) { | ||
if (isNaN(max) || max < 0) { | ||
throw new TypeError("Invalid max value"); | ||
} | ||
|
||
if (isNaN(ttl) || ttl < 0) { | ||
throw new TypeError("Invalid ttl value"); | ||
} | ||
|
||
return new LRU(max, ttl); | ||
} | ||
|
||
module.exports = factory; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignore the removal of star, this mainly adds tgz to ignore list.