Nuptial Predicament Mediation

    @thi.ng/bitfield
    TypeScript icon, indicating that this package has built-in type declarations

    2.2.14 • Public • Published

    bitfield

    npm version npm downloads Twitter Follow

    This project is part of the @thi.ng/umbrella monorepo.

    About

    1D / 2D bit field implementations.

    All implementations are backed by typed arrays. Due to Uint32Array backing the width is always rounded to a multiple of 32.

    Status

    STABLE - used in production

    Search or submit any issues for this package

    Related packages

    • @thi.ng/adjacency - Sparse & bitwise adjacency matrices and related functions for directed & undirected graphs

    Installation

    yarn add @thi.ng/bitfield

    ES module import:

    <script type="module" src="https://cdn.skypack.dev/@thi.ng/bitfield"></script>

    Skypack documentation

    For Node.js REPL:

    # with flag only for < v16
    node --experimental-repl-await
    
    > const bitfield = await import("@thi.ng/bitfield");
    

    Package sizes (brotli'd, pre-treeshake): ESM: 1.18 KB

    Dependencies

    API

    Generated API docs

    import { BitField, BitMatrix } from "@thi.ng/bitfield";
    
    // size always rounded up to a multiple of 32
    const field = new BitField(16);
    
    field.setAt(0);
    
    // if 2nd arg is false, the bit will be cleared
    // setAt returns non-zero value if bit was previously set
    field.setAt(31, true);
    // 0
    
    // returns non-zero value if bit is set
    field.at(0)
    // -2147483648
    
    field.at(1)
    // 0
    
    field.toString();
    // 10000000000000000000000000000001
    
    field.resize(64)
    // 1000000000000000000000000000000100000000000000000000000000000000
    
    const mat = new BitMatrix(8, 32);
    for(let i = 0; i < 8; i++) mat.setAt(i, i);
    
    mat.at(7, 7);
    // 16777216
    
    mat.toString();
    // 10000000000000000000000000000000
    // 01000000000000000000000000000000
    // 00100000000000000000000000000000
    // 00010000000000000000000000000000
    // 00001000000000000000000000000000
    // 00000100000000000000000000000000
    // 00000010000000000000000000000000
    // 00000001000000000000000000000000

    Authors

    Karsten Schmidt

    If this project contributes to an academic publication, please cite it as:

    @misc{thing-bitfield,
      title = "@thi.ng/bitfield",
      author = "Karsten Schmidt",
      note = "https://thi.ng/bitfield",
      year = 2016
    }

    License

    © 2016 - 2022 Karsten Schmidt // Apache Software License 2.0

    Install

    npm i @thi.ng/bitfield

    DownloadsWeekly Downloads

    67

    Version

    2.2.14

    License

    Apache-2.0

    Unpacked Size

    38.4 kB

    Total Files

    12

    Last publish

    Collaborators

    • thi.ng