
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
weak-flyweight-set
Advanced tools
The `WeakFlyweightSet` object holds weak references to similar objects.
The WeakFlyweightSet
object holds weak references to similar objects.
A weak reference to an object is a reference that does not prevent the object from being reclaimed by the garbage collector. In contrast, a normal (or strong) reference keeps an object in memory.
Flyweight is a structural design pattern that lets you fit more objects into the available amount of RAM by sharing common parts of state between multiple objects instead of keeping all of the data in each object.
The WeakFlyweightSet
is based on Set, WeakRef and FinalizationRegistry objects.
npm i weak-flyweight-set
const set = new WeakFlyweightSet();
let valueObject = {key1: 'value: 1', key2: 'value: 2'};
set.add(valueObject);
// all of the following calls return a reference to the same object
set.get({key1: 'value: 1', key2: 'value: 2'});
set.use({key1: 'value: 1', key2: 'value: 2'});
valueObject = null;
// ...
// GC reclaims space
// ...
// returns undefined
set.get({key1: 'value: 1', key2: 'value: 2'});
// return a reference to a new object
set.use({key1: 'value: 1', key2: 'value: 2'});
Returns the number of values in the WeakFlyweightSet
object.
:warning: Number of values is not precise due to nature of
FinalizationRegistry
object.
The add()
method adds an object to a WeakFlyweightSet
object.
The get()
method returns a reference to a similar object from a WeakFlyweightSet
object or undefined.
The use()
method returns a reference to a similar object from a WeakFlyweightSet
object or adds the specified object to the set and returns a reference to it.
The has()
method returns a boolean indicating whether a similar object exists or not.
The delete()
method removes a similar object from a WeakFlyweightSet
.
The values()
method returns a new Iterator
object that contains the values for each element in the WeakFlyweightSet
object in insertion order.
The forEach()
method executes a provided function once per each value in the WeakFlyweightSet
object, in insertion order.
The clear()
method removes all elements from a WeakFlyweightSet
object.
WeakFlyweightSet is MIT licensed.
FAQs
The `WeakFlyweightSet` object holds weak references to similar objects.
We found that weak-flyweight-set demonstrated a not healthy version release cadence and project activity because the last version was released 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
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.