Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
fast-linked-list
Advanced tools
Readme
General purpose, but clean doubly Linked List implementation for the web (3.4kB), performing decently well in benchmarks.
Please note that the length of the list is intentionally (by default) not being computed.
Token#remove()
has no way of mutating the length of the list, as it does not have a reference to it's parent list, only it's siblings. If you need this, use theLengthLinkedList
export, that functions analog, but provides a length attribute. This is a tradeoff between performance and functionality.
$ npm i fast-linked-list
For simple usage, the Token architecture is abstracted away.
import LinkedList from "fast-linked-list"
const ls = new LinkedList("b", "c")
const dElem = ls.push("a")
ls.toArray() // ["b", "c", "a"]
dElem.remove() // true (meaning successfully removed)
dElem.remove() // false
const dElem2 = ls.unshift(dElem.value)
for (const elem of ls) {
console.log(elem) // "a", "b", "c"
}
ls.reverse()
const addedElems = ls.pushBulk(["x", "y", "z"])
ls.toArray() // ["c", "b", "a", "x", "y", "z"]
addedElems[1].remove()
ls.toArray() // ["c", "b", "a", "x", "z"]
ls.pop() // "z"
ls.shift() // "c"
ls.first // "b"
ls.last // "x"
ls.reverse().forEach((e) => {
console.log(e) // "x", "a", "b"
})
const clone = new LinkedList(ls)
ls.clear()
Note that reverse()
does not mutate the list, but only inverts all basic i/o functions of the list. E.g.: push()
becomes unshift()
and first
becomes last
. Hence the reverse()
call performs with a time complexity of O(1).
A Token can only exsist within one LinkedList. Appending it somewhere else will remove it from the current list.
import LinkedList, { Token } from "fast-linked-list"
const ls1 = new LinkedList("ls", "1")
const ls2 = new LinkedList("ls", "2")
const token = new Token("added")
ls1.pushToken(token); ls1.toArray() // ["ls", "1", "added"]
ls2.pushToken(token); ls2.toArray() // ["ls", "2", "added"]
ls1.toArray() // ["ls", "1"]
token.insertBefore("before")
ls2.toArray() // ["ls", "1", "before", "added"]
// Search for a value whose Token is unknown and remove it. Preferably keep a reference to the token if you plan to remove it (as this is O(n)).
ls2.forEach((val, tok) => {
if (val === "ls") tok.remove()
})
All feedback is appreciated. Create a pull request or write an issue.
FAQs
General purpose, but clean doubly Linked List implementation for the web.
The npm package fast-linked-list receives a total of 42 weekly downloads. As such, fast-linked-list popularity was classified as not popular.
We found that fast-linked-list demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.