markdown update
This commit is contained in:
parent
4f4fddcbcf
commit
7db35956e1
39
README.md
39
README.md
|
|
@ -6,11 +6,12 @@ This TypeScript library provides a bitmap implementation (`Bitmap`) that allows
|
||||||
|
|
||||||
#### Features
|
#### Features
|
||||||
|
|
||||||
- **Set Operations:** Supports set, remove, contains, and clear operations on the bitmap.
|
- **Set Operations:** `set`, `remove`, `contains`, and `clear` operations on the bitmap.
|
||||||
- **Logical Operations:** Provides AND, AND-NOT, OR, and XOR operations between bitmaps.
|
- **Logical Operations:** `and`, `andNot`, `or`, and `xor` operations between bitmaps.
|
||||||
- **Iteration and Filtering:** Includes range iteration and filtering based on user-defined conditions.
|
- **Iteration and Filtering:** `range` iteration, generator-based iteration via `[Symbol.iterator]`, and `filter` based on user-defined conditions.
|
||||||
- **Counting and Extremes:** Methods to count set bits (`count`), find the minimum and maximum set bit (`min`, `max`), as well as the minimum and maximum unset bit (`minZero`, `maxZero`).
|
- **Count and Extremes:** Methods to count set bits (`count`), find the minimum and maximum set bit (`min`, `max`), as well as the minimum and maximum unset bit (`minZero`, `maxZero`).
|
||||||
- **Cloning:** Supports cloning of the bitmap instance.
|
- **Cloning:** Supports cloning of the bitmap instance.
|
||||||
|
- **Iterable Support:** Can be used directly in `for...of` loops and spread syntax (`[...bitmap]`) for convenient iteration over set bits.
|
||||||
|
|
||||||
#### Installation
|
#### Installation
|
||||||
|
|
||||||
|
|
@ -18,7 +19,7 @@ You can install the library via npm:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install bitmap-index
|
npm install bitmap-index
|
||||||
```
|
````
|
||||||
|
|
||||||
#### Usage Example
|
#### Usage Example
|
||||||
|
|
||||||
|
|
@ -46,12 +47,20 @@ const andResult = bitmap.and(otherBitmap); // Bitmap with bits [5, 10]
|
||||||
const orResult = bitmap.or(otherBitmap); // Bitmap with bits [2, 5, 10]
|
const orResult = bitmap.or(otherBitmap); // Bitmap with bits [2, 5, 10]
|
||||||
const xorResult = bitmap.xor(otherBitmap); // Bitmap with bits [2]
|
const xorResult = bitmap.xor(otherBitmap); // Bitmap with bits [2]
|
||||||
|
|
||||||
// Iterate over set bits within a range
|
// Iterate over set bits using range
|
||||||
bitmap.range((x) => {
|
bitmap.range((x) => {
|
||||||
console.log(`Bit ${x} is set`);
|
console.log(`Bit ${x} is set`);
|
||||||
return true; // Continue iterating
|
return true; // Continue iterating
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Iterate using for...of (generator)
|
||||||
|
for (const bit of bitmap) {
|
||||||
|
console.log(`Iterated bit: ${bit}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spread operator
|
||||||
|
const bitsArray = [...bitmap]; // [2, 5, 10]
|
||||||
|
|
||||||
// Filter based on a condition
|
// Filter based on a condition
|
||||||
bitmap.filter((x) => x % 2 === 0); // Remove odd-numbered bits
|
bitmap.filter((x) => x % 2 === 0); // Remove odd-numbered bits
|
||||||
|
|
||||||
|
|
@ -67,19 +76,18 @@ bitmap.clear();
|
||||||
|
|
||||||
// Clone the bitmap
|
// Clone the bitmap
|
||||||
const clonedBitmap = bitmap.clone();
|
const clonedBitmap = bitmap.clone();
|
||||||
|
|
||||||
// Further operations can be performed on clonedBitmap...
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### API Documentation
|
#### API Documentation
|
||||||
|
|
||||||
- **Bitmap Class**
|
* **Bitmap Class**
|
||||||
- **Constructor:** `new Bitmap(size: number = 32)`
|
|
||||||
- **Set Operations:** `set(x: number)`, `remove(x: number)`, `contains(x: number)`, `clear()`
|
* **Constructor:** `new Bitmap(size: number = 32)`
|
||||||
- **Logical Operations:** `and(bitmap: Bitmap)`, `andNot(bitmap: Bitmap)`, `or(bitmap: Bitmap)`, `xor(bitmap: Bitmap)`
|
* **Set Operations:** `set(x: number)`, `remove(x: number)`, `contains(x: number)`, `clear()`
|
||||||
- **Iteration and Filtering:** `range(fn: (x: number) => boolean)`, `filter(fn: (x: number) => boolean)`
|
* **Logical Operations:** `and(bitmap: Bitmap)`, `andNot(bitmap: Bitmap)`, `or(bitmap: Bitmap)`, `xor(bitmap: Bitmap)`
|
||||||
- **Count and Extremes:** `count()`, `min()`, `max()`, `minZero()`, `maxZero()`
|
* **Iteration and Filtering:** `range(fn: (x: number) => boolean)`, `filter(fn: (x: number) => boolean)`, `[Symbol.iterator](): Iterator<number>`
|
||||||
- **Cloning:** `clone(): Bitmap`
|
* **Count and Extremes:** `count()`, `min()`, `max()`, `minZero()`, `maxZero()`
|
||||||
|
* **Cloning:** `clone(): Bitmap`
|
||||||
|
|
||||||
#### Note
|
#### Note
|
||||||
|
|
||||||
|
|
@ -89,7 +97,6 @@ This library is designed for bitmap indexing operations and is not related to im
|
||||||
|
|
||||||
Feel free to contribute, report issues, or suggest improvements on [GitHub](https://github.com/yazmeyaa/bitmap-index).
|
Feel free to contribute, report issues, or suggest improvements on [GitHub](https://github.com/yazmeyaa/bitmap-index).
|
||||||
|
|
||||||
|
|
||||||
[npm-image]: https://img.shields.io/npm/v/bitmap-index.svg?style=flat-square
|
[npm-image]: https://img.shields.io/npm/v/bitmap-index.svg?style=flat-square
|
||||||
[npm-url]: https://npmjs.org/package/bitmap-index
|
[npm-url]: https://npmjs.org/package/bitmap-index
|
||||||
[downloads-image]: https://img.shields.io/npm/dm/bitmap-index.svg?style=flat-square
|
[downloads-image]: https://img.shields.io/npm/dm/bitmap-index.svg?style=flat-square
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue