structurae
Advanced tools
Comparing version 0.0.3 to 0.0.4
const SortedArray = require('./lib/sorted-array'); | ||
const PackedInt = require('./lib/packed-int'); | ||
const GridMixin = require('./lib/grid'); | ||
@@ -7,2 +8,3 @@ module.exports = { | ||
PackedInt, | ||
GridMixin, | ||
}; |
@@ -12,3 +12,3 @@ /** | ||
* Float32ArrayConstructor| | ||
* Float64ArrayConstructor} IndexedCollectionConstructor | ||
* Float64ArrayConstructor} CollectionConstructor | ||
*/ | ||
@@ -27,9 +27,15 @@ | ||
* Float32Array| | ||
* Float64Array} IndexedCollection | ||
* Float64Array} Collection | ||
*/ | ||
/** | ||
* @typedef {Array} Coordinates | ||
* @property {number} 0 row index | ||
* @property {number} 1 column index | ||
*/ | ||
/** | ||
* Creates a Grid class extending a given Array-like class. | ||
* | ||
* @param {IndexedCollectionConstructor} Base | ||
* @param {CollectionConstructor} Base | ||
* @returns {Grid} | ||
@@ -40,5 +46,5 @@ * @example | ||
*/ | ||
function GridFactory(Base) { | ||
function GridMixin(Base) { | ||
/** | ||
* @extends IndexedCollectionConstructor | ||
* @extends CollectionConstructor | ||
*/ | ||
@@ -54,3 +60,3 @@ class Grid extends Base { | ||
* @param {*} [options.pad=0] the initial value of cells | ||
* @param {IndexedCollection} [data] | ||
* @param {Collection} [data] | ||
* @example | ||
@@ -150,3 +156,3 @@ * | ||
* @param {number} index | ||
* @returns {Array<number>} coordinates | ||
* @returns {Coordinates} coordinates | ||
* @example | ||
@@ -199,3 +205,3 @@ * const a = ArrayGrid({ rows: 3, columns: 2, pad: 3}); | ||
/** | ||
* @type {IndexedCollection} | ||
* @type {CollectionConstructor} | ||
*/ | ||
@@ -257,2 +263,2 @@ static get [Symbol.species]() { | ||
module.exports = GridFactory; | ||
module.exports = GridMixin; |
@@ -9,3 +9,3 @@ /** | ||
* @private | ||
* The largest safe integer for bitwise operations. | ||
* @type {number} The largest safe integer for bitwise operations. | ||
*/ | ||
@@ -16,3 +16,3 @@ const SIGN_BIT = 2147483647; | ||
* @private | ||
* The maximum safe size for bitwise operations on standard numbers. | ||
* @type {number} The maximum safe size for bitwise operations on standard numbers. | ||
*/ | ||
@@ -23,3 +23,3 @@ const BITWISE_SIZE = 31; | ||
* @private | ||
* The maximum safe size for standard numbers in bits. | ||
* @type {number} The maximum safe size for standard numbers in bits. | ||
*/ | ||
@@ -29,10 +29,32 @@ const MAX_SIZE = 53; | ||
/** | ||
* @typedef {number | BigInt} AnyNumber | ||
*/ | ||
/** | ||
* @typedef {number | string} FieldName | ||
*/ | ||
/** | ||
* @typedef {Object<string, number>} UnpackedInt | ||
*/ | ||
/** | ||
* @typedef {Object} Field | ||
* @property {FieldName} name name of the field | ||
* @property {number} [size] size in bits | ||
*/ | ||
/** | ||
* @typedef {Array} Matcher | ||
* @property {number} 0 value | ||
* @property {number} 1 mask | ||
* @property {AnyNumber} 0 value | ||
* @property {AnyNumber} 1 mask | ||
*/ | ||
/** | ||
* @typedef {Object<string, AnyNumber>} Masks | ||
*/ | ||
class PackedInt { | ||
/** | ||
* @param {number|BigInt|Array<number>} data | ||
* @param {AnyNumber|Array<number>} [data=0] | ||
* @example | ||
@@ -50,3 +72,3 @@ * | ||
*/ | ||
constructor(data) { | ||
constructor(data = 0) { | ||
const { isInitialized } = this.constructor; | ||
@@ -65,3 +87,3 @@ if (!isInitialized) this.constructor.initialize(); | ||
* | ||
* @param {string|number} field name of the field | ||
* @param {Field} field name of the field | ||
* @returns {number} value value of the field | ||
@@ -90,3 +112,3 @@ * @example | ||
* | ||
* @param {string} field name of the field | ||
* @param {Field} field name of the field | ||
* @param {number} value value of the field | ||
@@ -117,3 +139,3 @@ * @returns {PackedInt} the instance | ||
* | ||
* @param {...string|number} fields names of the fields to check | ||
* @param {...Field} fields names of the fields to check | ||
* @returns {boolean} whether all the specified fields are set in the instance | ||
@@ -145,3 +167,3 @@ * @example | ||
* | ||
* @param {Object<string,number>|Matcher} matcher an object with key-value pairs, | ||
* @param {UnpackedInt|Matcher} matcher an object with key-value pairs, | ||
* or an array of precomputed matcher values | ||
@@ -182,3 +204,3 @@ * @returns {boolean} whether the instance matches with the provided fields | ||
* @private | ||
* @returns {number|BigInt} the numerical value of the instance | ||
* @returns {AnyNumber} the numerical value of the instance | ||
*/ | ||
@@ -193,3 +215,3 @@ toValue() { | ||
* with field names as properties with corresponding values. | ||
* @returns {Object<string, number>} the object representation of the instance | ||
* @returns {UnpackedInt} the object representation of the instance | ||
* @example | ||
@@ -213,4 +235,4 @@ * | ||
* | ||
* @param {Array<number>} data the list of numbers to encode | ||
* @returns {number} encoded number | ||
* @param {Array<AnyNumber>} data the list of numbers to encode | ||
* @returns {AnyNumber} encoded number | ||
* @example | ||
@@ -240,4 +262,4 @@ * | ||
* | ||
* @param {number} data encoded number | ||
* @returns {Object<string, number>} object representation | ||
* @param {AnyNumber} data encoded number | ||
* @returns {UnpackedInt} object representation | ||
* @example | ||
@@ -269,3 +291,3 @@ * | ||
* | ||
* @param {Array<number>|Object<string,number>} data pairs of field name and value to check | ||
* @param {AnyNumber|UnpackedInt} data pairs of field name and value to check | ||
* @returns {boolean} whether all pairs are valid | ||
@@ -378,3 +400,3 @@ * @example | ||
* | ||
* @param {Object<string, number>} matcher an object containing field names and their values | ||
* @param {UnpackedInt} matcher an object containing field names and their values | ||
* @returns {Matcher} an array of precomputed values | ||
@@ -402,3 +424,3 @@ */ | ||
* | ||
* @param {number|BigInt} value a value to check | ||
* @param {AnyNumber} value a value to check | ||
* @param {Matcher} matcher a precomputed set of values | ||
@@ -425,9 +447,3 @@ * @returns {boolean} | ||
/** | ||
* @typedef {Object} FieldDescription | ||
* @property {string} name field name | ||
* @property {number} size size of the field in bits | ||
*/ | ||
/** @type {Array<number>|Array<FieldDescription>} */ | ||
/** @type {Array<FieldName>|Array<Field>} */ | ||
PackedInt.fields = Array.from({ length: BITWISE_SIZE }, (e, i) => i); | ||
@@ -438,18 +454,18 @@ | ||
/** @type {number|BigInt} */ | ||
/** @type {AnyNumber} */ | ||
PackedInt.zero = 0; | ||
/** @type {number|BigInt} */ | ||
/** @type {AnyNumber} */ | ||
PackedInt.one = 1; | ||
/** @type {number|BigInt} */ | ||
/** @type {AnyNumber} */ | ||
PackedInt.two = 2; | ||
/** @type {Object<string, number>} */ | ||
/** @type {Masks} */ | ||
PackedInt.masks = undefined; | ||
/** @type {number|BigInt} */ | ||
/** @type {AnyNumber} */ | ||
PackedInt.mask = 1073741824; | ||
/** @type {Object<string, number>} */ | ||
/** @type {Masks} */ | ||
PackedInt.offsets = undefined; | ||
@@ -456,0 +472,0 @@ |
/** | ||
* @typedef {function(a: *, b: *): number} Comparator | ||
*/ | ||
/** | ||
* Extends built-in Array to efficiently handle sorted data. | ||
@@ -184,3 +188,3 @@ * | ||
* @private | ||
* @param {Function} compareFunction the function to use for comparison | ||
* @param {Comparator} compareFunction the function to use for comparison | ||
* @returns {void} | ||
@@ -255,3 +259,3 @@ */ | ||
* @param {boolean} [symmetric=false] whether to get symmetric difference. | ||
* @param {Function} [comparator] the comparator static used to sort the arrays | ||
* @param {Comparator} [comparator] the comparator static used to sort the arrays | ||
* @returns {Array} the difference of the arrays | ||
@@ -308,3 +312,3 @@ * @example | ||
* @param {boolean} [symmetric=false] whether to use symmetric difference | ||
* @param {Function} [comparator] the comparator static used to sort the arrays | ||
* @param {Comparator} [comparator] the comparator static used to sort the arrays | ||
* @returns {number} the amount of differing elements | ||
@@ -326,3 +330,3 @@ * @example | ||
* @param {*} target the target value to search for | ||
* @param {Function} [comparator] a custom comparator | ||
* @param {Comparator} [comparator] a custom comparator | ||
* @param {boolean} [rank] whether to return the element's rank if the element isn't found | ||
@@ -363,3 +367,3 @@ * @param {number} [start] the start position of the search | ||
* @param {Array} b the second array | ||
* @param {Function} [comparator] the comparator static used to sort the arrays | ||
* @param {Comparator} [comparator] the comparator static used to sort the arrays | ||
* @returns {Array} the intersection of the arrays | ||
@@ -400,3 +404,3 @@ * @example | ||
* @param {Array} b the second array | ||
* @param {Function} [comparator] the comparator static used to sort the arrays | ||
* @param {Comparator} [comparator] the comparator static used to sort the arrays | ||
* @returns {number} the amount of different elements | ||
@@ -433,3 +437,3 @@ * @example | ||
* @param {number} [end] the ending item | ||
* @param {Function} [comparator] a custom comparator | ||
* @param {Comparator} [comparator] a custom comparator | ||
* @returns {Array} the range of items | ||
@@ -458,3 +462,3 @@ * @example | ||
* @param {*} target the target value to search for | ||
* @param {Function} [comparator] a custom comparator | ||
* @param {Comparator} [comparator] a custom comparator | ||
* @returns {number} the rank of the searched item | ||
@@ -480,3 +484,3 @@ * @example | ||
* @param {boolean} [unique=false] whether to avoid duplicating items when merging unique arrays | ||
* @param {Function} [comparator] the comparator static used to sort the arrays | ||
* @param {Comparator} [comparator] the comparator static used to sort the arrays | ||
* @returns {Array} the union of the arrays | ||
@@ -531,3 +535,3 @@ * @example | ||
* @param {Array} arr the sorted array | ||
* @param {Function} [comparator] a custom comparator | ||
* @param {Comparator} [comparator] a custom comparator | ||
* @returns {Array} the sorted array without duplicates | ||
@@ -568,3 +572,3 @@ * @example | ||
* @param {Array} arr the array to check | ||
* @param {Function} [comparator] a custom comparator | ||
* @param {Comparator} [comparator] a custom comparator | ||
* @returns {boolean} whether the array is sorted | ||
@@ -588,3 +592,3 @@ * | ||
* @param {Array} arr the array to check | ||
* @param {Function} [comparator] a custom comparator | ||
* @param {Comparator} [comparator] a custom comparator | ||
* @returns {boolean} whether the array has duplicating elements | ||
@@ -591,0 +595,0 @@ * @example |
{ | ||
"name": "structurae", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Data structures for performance-sensitive modern JavaScript applications.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -43,3 +43,3 @@ # Structurae | ||
// send data as the second parameter to instantiate a grid with data: | ||
const dataGrid = new ArrayGrid([{rows: 5, columns: 4 }, 1, 2, 3, 4, 5, 6, 7, 8]); | ||
const dataGrid = new ArrayGrid({rows: 5, columns: 4 }, [1, 2, 3, 4, 5, 6, 7, 8]); | ||
grid.length | ||
@@ -46,0 +46,0 @@ //=> 20 |
52335
9
1315