
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Dichotomid helps you find the first free id of something, efficiently.
Imagine you have a directory with files named file1
, file2
, file3
, ... and you want to find the first free fileN
:
// 🐌 Naive implementation, do not do this 🐌
let i = 1;
while (fs.existsSync(`file${i}`)) {
i++;
}
console.log(`file${i} is the first free`);
This implementation works, but can be mathematically optimized, and that's what dichotomid is for:
// 🐎 Optimized implementation 🐎
import { dichotomid } from "dichotomid";
let i = dichotomid((i) => fs.existsSync(`file${i}`));
console.log(`file${i} is the first free`);
Dichotomid relies on binary search to find the first free id in the least amount of tests. Indeed, if file1
to file999
are all taken, it would take 1000 existsSync
calls to figure it out naively. Dichotomid will find the value in 30 call.
import { dichotomid } from "dichotomid";
let op = 0;
let validator = (n) => {
op++;
return n >= 1000; // The first free id is 1000
};
let id = dichotomid(validator);
console.log(op); // 30
Three functions are made available: dichotomid
(default export), dichotomidSync
and dichotomidAsync
.
dichotomid
works for both synchronous and asynchronous validators. It returns a number
if the validator is synchronous, or a Promise<number>
if the validator is asynchronous.
dichotomid
has a fail safe if the value offered to the validator exceeds MAX_SAFE_INTEGER
.FAQs
Dichotomid helps you find the first free id of something, efficiently.
The npm package dichotomid receives a total of 14 weekly downloads. As such, dichotomid popularity was classified as not popular.
We found that dichotomid 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
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.