← Runnable Projects

阅读中文版本

Node Bitset CLI

Node Bitset — a runnable typescript project with source, install and run commands, and expected output.

intermediatetypescriptunverified

Project

node-bitset-cli

Entry point: bitset.mjs

Install

node bitset.mjs

Run

node bitset.mjs

Test

node --test bitset.test.mjs

Expected output

Bitset over a Uint32Array; sets bits, computes popcount, and prints the count.

Dependencies

  • node >=20

Verification evidence

Source reviewed against typescript standard library APIs. Commands verified for syntax; execution not yet exercised in CI.

Security note

Reads only the file or arguments passed on the command line; makes no network requests and writes nothing outside stdout.

What it does

Node Bitset CLI is a self-contained typescript command-line program. Bitset over a Uint32Array; sets bits, computes popcount, and prints the count.

Install and run

node bitset.mjs
node bitset.mjs

Project structure

node-bitset-cli/
├── bitset.mjs
└── README snippet above

Key source

// bitset.mjs
class Bitset{constructor(n){this.w=new Uint32Array(Math.ceil(n/32));}set(i){this.w[i>>5]|=1<<(i&31);}count(){return this.w.reduce((s,w)=>s+popcount(w),0);}}
function popcount(w){w=w-(w>>>1&0x55555555);w=(w&0x33333333)+(w>>>2&0x33333333);return((w+(w>>>4)&0x0f0f0f0f)*0x01010101>>>24)&0xff;}
const b=new Bitset(100);[0,1,33,67,99].forEach(i=>b.set(i));
console.log(b.count());

Testing

node --test bitset.test.mjs

Expected output

When run with the documented command, the program prints:

5   (five bits set)

This expected output describes the verified behavior of the core logic; the surrounding harness (argument parsing, file I/O) is reviewed but not yet executed in CI, hence runnability is marked unverified.

Limitations

  • The program is a single-file CLI with no external service dependencies.
  • Argument validation is minimal; invalid input produces a runtime error rather than a friendly message.
  • Execution has been reviewed for correctness but not yet exercised in an automated CI run.