
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Estimate the number of distinct values in a set using the simple and space-efficient CVM algorithm
Estimate the number of distinct values in a set using the simple and space-efficient CVM algorithm.
NPM:
npm install cvm-lib
Yarn:
yarn add cvm-lib
JSR:
jsr add @rojas/cvm
See the examples/ directory for all examples.
Estimate unique words in Shakespeare's Hamlet:
node ./examples/hamlet/index.js
Estimate unique integers among 1 million random integers.
node ./examples/hamlet/index.js
calculateCapacity(n, epsilon?, delta?)
Calculates the space required to estimate the number of distinct values in a set with a given accuracy and confidence.
n
: The total number of values in the set, or an estimate if unknown. Must be a positive number.epsilon
(optional): An estimate's relative error. Controls accuracy. Must be between 0 and 1. Defaults to 0.05
.delta
(optional): The probability an estimate is not accurate. Controls confidence. Must be between 0 and 1. Defaults to 0.01
.Estimator<T>
Estimates the number of distinct values in a set using the CVM algorithm.
Constructors
new (capacity)
: Create an instance with a given capacity. Must be a positive integer.new (config)
: Create an instance using a config object.Properties
capacity
: Gets the maximum number of samples in memory.randomFn
: Gets or sets the random number generator function (e.g. Math.random
).sampleRate
Gets the base sample rate (e.g. 0.5
).size
: Gets the number of samples in memory.Methods
add(value)
: Adds a value.clear()
: Clears/resets the instance.estimate()
: Gets the estimated number of distinct values.EstimatorConfig<T>
A configuration object used to create Estimator
instances.
capacity
: The maximum number of samples in memory. Must be a positive integer.randomFn
(optional): The random number generator function. Should return random or pseudorandom values between 0 and 1.sampleRate
(optional): The sampling rate for managing samples. Must be between 0 and 1.
0.5
, the more it's affected. If capacity
was calculated via calculateCapacity
,
expected accuracy / confidence may be invalidated.storage
(optional): An object that implements SampleSet
for storing samples.SampleSet<T>
Represents a generic set for storing samples.
size
: The number of values in the set.add(value)
: Adds a value to the set.clear()
: Clears all values from the set.delete(value)
: Removes a specified value from the set.[Symbol.iterator]()
: Iterates through the set's values.Contributions are welcome!
Questions / Dicussions: Please contact us via GitHub discussions.
Bug Reports: Please use the GitHub issue tracker to report any bugs. Include a detailed description and any relevant code snippets or logs.
Feature Requests: Please submit feature requests as issues, clearly describing the feature and its potential benefits.
Pull Requests: Please ensure your code adheres to the existing style of the project and include any necessary tests and documentation.
For more information, check out the contributor's guide.
git clone git@github.com:havelessbemore/cvm-lib.git
cd cvm-lib
npm install
npm run build
This will output ECMAScript (.mjs
) and CommonJS (.cjs
) modules in the dist/
directory.
To run the code linter:
npm run lint
To automatically fix linting issues, run:
npm run format
To run tests:
npm test
To run tests with a coverage report:
npm run test:coverage
A coverage report is generated at ./coverage/index.html
.
0.1.2 (2025-08-03)
FAQs
Estimate the number of distinct values in a set using the simple and space-efficient CVM algorithm
The npm package cvm-lib receives a total of 16 weekly downloads. As such, cvm-lib popularity was classified as not popular.
We found that cvm-lib 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.