@bentley/bentleyjs-core
Advanced tools
Comparing version 0.171.0 to 0.187.0
@@ -5,2 +5,122 @@ { | ||
{ | ||
"version": "0.187.0", | ||
"tag": "@bentley/bentleyjs-core_v0.187.0", | ||
"date": "Tue, 15 Jan 2019 15:18:59 GMT", | ||
"comments": {} | ||
}, | ||
{ | ||
"version": "0.186.0", | ||
"tag": "@bentley/bentleyjs-core_v0.186.0", | ||
"date": "Mon, 14 Jan 2019 23:09:10 GMT", | ||
"comments": { | ||
"none": [ | ||
{ | ||
"comment": "Removed IModelDb's cache of accessToken. For long running operations like AutoPush, the user must explicitly supply an IAccessTokenManager to keep the token current. " | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"version": "0.185.0", | ||
"tag": "@bentley/bentleyjs-core_v0.185.0", | ||
"date": "Fri, 11 Jan 2019 18:29:00 GMT", | ||
"comments": { | ||
"none": [ | ||
{ | ||
"comment": "Optimize Id64String operations and supply specialized, optimized collection types." | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"version": "0.184.0", | ||
"tag": "@bentley/bentleyjs-core_v0.184.0", | ||
"date": "Thu, 10 Jan 2019 22:46:17 GMT", | ||
"comments": {} | ||
}, | ||
{ | ||
"version": "0.183.0", | ||
"tag": "@bentley/bentleyjs-core_v0.183.0", | ||
"date": "Mon, 07 Jan 2019 21:49:21 GMT", | ||
"comments": {} | ||
}, | ||
{ | ||
"version": "0.182.0", | ||
"tag": "@bentley/bentleyjs-core_v0.182.0", | ||
"date": "Mon, 07 Jan 2019 13:31:34 GMT", | ||
"comments": {} | ||
}, | ||
{ | ||
"version": "0.181.0", | ||
"tag": "@bentley/bentleyjs-core_v0.181.0", | ||
"date": "Fri, 04 Jan 2019 13:02:40 GMT", | ||
"comments": {} | ||
}, | ||
{ | ||
"version": "0.180.0", | ||
"tag": "@bentley/bentleyjs-core_v0.180.0", | ||
"date": "Wed, 02 Jan 2019 15:18:23 GMT", | ||
"comments": { | ||
"none": [ | ||
{ | ||
"comment": "Enable usage of custom collection classes inside for..of loops." | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"version": "0.179.0", | ||
"tag": "@bentley/bentleyjs-core_v0.179.0", | ||
"date": "Wed, 19 Dec 2018 18:26:14 GMT", | ||
"comments": { | ||
"none": [ | ||
{ | ||
"comment": "Fix issue where all event listeners are removed." | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"version": "0.178.0", | ||
"tag": "@bentley/bentleyjs-core_v0.178.0", | ||
"date": "Thu, 13 Dec 2018 22:06:10 GMT", | ||
"comments": {} | ||
}, | ||
{ | ||
"version": "0.177.0", | ||
"tag": "@bentley/bentleyjs-core_v0.177.0", | ||
"date": "Wed, 12 Dec 2018 17:21:31 GMT", | ||
"comments": {} | ||
}, | ||
{ | ||
"version": "0.176.0", | ||
"tag": "@bentley/bentleyjs-core_v0.176.0", | ||
"date": "Mon, 10 Dec 2018 21:19:45 GMT", | ||
"comments": {} | ||
}, | ||
{ | ||
"version": "0.175.0", | ||
"tag": "@bentley/bentleyjs-core_v0.175.0", | ||
"date": "Mon, 10 Dec 2018 17:08:55 GMT", | ||
"comments": {} | ||
}, | ||
{ | ||
"version": "0.174.0", | ||
"tag": "@bentley/bentleyjs-core_v0.174.0", | ||
"date": "Mon, 10 Dec 2018 13:24:09 GMT", | ||
"comments": {} | ||
}, | ||
{ | ||
"version": "0.173.0", | ||
"tag": "@bentley/bentleyjs-core_v0.173.0", | ||
"date": "Thu, 06 Dec 2018 22:03:29 GMT", | ||
"comments": {} | ||
}, | ||
{ | ||
"version": "0.172.0", | ||
"tag": "@bentley/bentleyjs-core_v0.172.0", | ||
"date": "Tue, 04 Dec 2018 17:24:39 GMT", | ||
"comments": {} | ||
}, | ||
{ | ||
"version": "0.171.0", | ||
@@ -7,0 +127,0 @@ "tag": "@bentley/bentleyjs-core_v0.171.0", |
# Change Log - @bentley/bentleyjs-core | ||
This log was last generated on Mon, 03 Dec 2018 18:52:58 GMT and should not be manually modified. | ||
This log was last generated on Tue, 15 Jan 2019 15:18:59 GMT and should not be manually modified. | ||
## 0.187.0 | ||
Tue, 15 Jan 2019 15:18:59 GMT | ||
*Version update only* | ||
## 0.186.0 | ||
Mon, 14 Jan 2019 23:09:10 GMT | ||
### Updates | ||
- Removed IModelDb's cache of accessToken. For long running operations like AutoPush, the user must explicitly supply an IAccessTokenManager to keep the token current. | ||
## 0.185.0 | ||
Fri, 11 Jan 2019 18:29:00 GMT | ||
### Updates | ||
- Optimize Id64String operations and supply specialized, optimized collection types. | ||
## 0.184.0 | ||
Thu, 10 Jan 2019 22:46:17 GMT | ||
*Version update only* | ||
## 0.183.0 | ||
Mon, 07 Jan 2019 21:49:21 GMT | ||
*Version update only* | ||
## 0.182.0 | ||
Mon, 07 Jan 2019 13:31:34 GMT | ||
*Version update only* | ||
## 0.181.0 | ||
Fri, 04 Jan 2019 13:02:40 GMT | ||
*Version update only* | ||
## 0.180.0 | ||
Wed, 02 Jan 2019 15:18:23 GMT | ||
### Updates | ||
- Enable usage of custom collection classes inside for..of loops. | ||
## 0.179.0 | ||
Wed, 19 Dec 2018 18:26:14 GMT | ||
### Updates | ||
- Fix issue where all event listeners are removed. | ||
## 0.178.0 | ||
Thu, 13 Dec 2018 22:06:10 GMT | ||
*Version update only* | ||
## 0.177.0 | ||
Wed, 12 Dec 2018 17:21:31 GMT | ||
*Version update only* | ||
## 0.176.0 | ||
Mon, 10 Dec 2018 21:19:45 GMT | ||
*Version update only* | ||
## 0.175.0 | ||
Mon, 10 Dec 2018 17:08:55 GMT | ||
*Version update only* | ||
## 0.174.0 | ||
Mon, 10 Dec 2018 13:24:09 GMT | ||
*Version update only* | ||
## 0.173.0 | ||
Thu, 06 Dec 2018 22:03:29 GMT | ||
*Version update only* | ||
## 0.172.0 | ||
Tue, 04 Dec 2018 17:24:39 GMT | ||
*Version update only* | ||
## 0.171.0 | ||
@@ -6,0 +94,0 @@ Mon, 03 Dec 2018 18:52:58 GMT |
@@ -12,4 +12,6 @@ /** @module Logging */ | ||
readonly activityId: string; | ||
/** The version id of the frontend application. */ | ||
readonly versionId: string; | ||
/** Construct a logging context, based on a given activityId. This should be called by RpcInvocation. */ | ||
constructor(activityId: string); | ||
constructor(activityId: string, versionId?: string); | ||
/** | ||
@@ -16,0 +18,0 @@ * Set or reset the current ActivityLoggingContext to be this object. Should be called by backend async functions and the functions that they call |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
@@ -14,4 +14,5 @@ *--------------------------------------------------------------------------------------------*/ | ||
/** Construct a logging context, based on a given activityId. This should be called by RpcInvocation. */ | ||
constructor(activityId) { | ||
constructor(activityId, versionId = "") { | ||
this.activityId = activityId; | ||
this.versionId = versionId; | ||
} | ||
@@ -29,4 +30,4 @@ /** The current activity context. */ | ||
} | ||
ActivityLoggingContext._current = new ActivityLoggingContext(""); | ||
ActivityLoggingContext._current = new ActivityLoggingContext("", ""); | ||
exports.ActivityLoggingContext = ActivityLoggingContext; | ||
//# sourceMappingURL=ActivityLoggingContext.js.map |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
@@ -5,0 +5,0 @@ *--------------------------------------------------------------------------------------------*/ |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
@@ -82,3 +82,3 @@ *--------------------------------------------------------------------------------------------*/ | ||
const listeners = this._listeners; | ||
let length = listeners.length; | ||
const length = listeners.length; | ||
let dropped = false; | ||
@@ -97,10 +97,7 @@ for (let i = 0; i < length; ++i) { | ||
} | ||
// if we had dropped listeners, remove them now | ||
if (dropped) { | ||
this._listeners.length = 0; | ||
listeners.forEach((ctx) => { if (ctx.listener) | ||
this._listeners.push(ctx); }); | ||
length = listeners.length; | ||
} | ||
} | ||
// if we had dropped listeners, remove them now | ||
if (dropped) { | ||
this._listeners = this._listeners.filter((ctx) => ctx.listener !== undefined); | ||
} | ||
this._insideRaiseEvent = false; | ||
@@ -107,0 +104,0 @@ } |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
@@ -294,3 +294,3 @@ *--------------------------------------------------------------------------------------------*/ | ||
})(IModelHubStatus = exports.IModelHubStatus || (exports.IModelHubStatus = {})); | ||
// iModelHub Services Errors | ||
// Authentication Errors | ||
var AuthStatus; | ||
@@ -297,0 +297,0 @@ (function (AuthStatus) { |
@@ -17,2 +17,3 @@ export * from "./Assert"; | ||
export * from "./Time"; | ||
export * from "./PriorityQueue"; | ||
/** @module Utils */ | ||
@@ -43,2 +44,6 @@ /** @docs-package-description | ||
/** | ||
* @docs-group-description Collections | ||
* Specialized, customizable collection classes like priority queues. | ||
*/ | ||
/** | ||
* @docs-group-description Utils | ||
@@ -45,0 +50,0 @@ * Miscellaneous utility classes. |
@@ -7,3 +7,3 @@ "use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
@@ -27,2 +27,3 @@ *--------------------------------------------------------------------------------------------*/ | ||
__export(require("./Time")); | ||
__export(require("./PriorityQueue")); | ||
/** @module Utils */ | ||
@@ -53,2 +54,6 @@ /** @docs-package-description | ||
/** | ||
* @docs-group-description Collections | ||
* Specialized, customizable collection classes like priority queues. | ||
*/ | ||
/** | ||
* @docs-group-description Utils | ||
@@ -55,0 +60,0 @@ * Miscellaneous utility classes. |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
@@ -5,0 +5,0 @@ *--------------------------------------------------------------------------------------------*/ |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
@@ -5,0 +5,0 @@ *--------------------------------------------------------------------------------------------*/ |
/** @module Utils */ | ||
/** | ||
* Basic comparison routine for numbers which treats two numbers as equal if the absolute value of their difference is less than the specified tolerance. | ||
* A function that returns a numerical value indicating how two objects are ordered in relation to one another. | ||
* Such functions are used by various collection classes in the iModel.js library. | ||
* Given values `lhs` and `rhs`, the function returns: | ||
* - Zero if lhs == rhs | ||
* - A negative number if lhs < rhs | ||
* - A positive number if lhs > rhs | ||
* | ||
* An OrderedComparator `must` implement [strict weak ordering](https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings), which can be summarized by the following rules: | ||
* - `compare(x, x)` returns zero. | ||
* - If `compare(x, y)` returns zero, then so does `compare(y, x)` (i.e., `x == y` implies `y == x`). | ||
* - If `compare(x, y)` returns non-zero, then `compare(y, x)` returns a value with an opposite sign (i.e., `x < y` implies `y > x`). | ||
* - If `compare(x, y)` and `compare(y, z)` return non-zero values with the same sign, then `compare(x, z)` returns a value with the same sign (i.e., `x < y < z` implies `x < z`). | ||
* | ||
* @see SortedArray | ||
* @see Dictionary | ||
* @see IndexMap | ||
* @see PriorityQueue | ||
*/ | ||
export declare type OrderedComparator<T, U = T> = (lhs: T, rhs: U) => number; | ||
/** | ||
* An [[OrderedComparator]] for numbers that treats two numbers as equal if the absolute value of their difference is less than a specified tolerance. | ||
* @hidden | ||
@@ -13,22 +33,3 @@ */ | ||
export declare function compareStrings(a: string, b: string): number; | ||
/** Interface adopted by a type T which supports ordered comparison. */ | ||
export interface Comparable<T> { | ||
/** Determine whether this object is considered equivalent to another object. | ||
* @param rhs The object to which to compare | ||
* @returns true if the objects are considered equivalent. | ||
*/ | ||
equals(rhs: T): boolean; | ||
/** Determine ordering of this object relative to another object. | ||
* Ordering is specified as a numerical value for which only the sign is meaningful. | ||
* A negative result indicates this object is ordered before the other object. | ||
* A positive result indicates this object is ordered after the other object. | ||
* A result of zero indicates the two objects are considered equivalent. | ||
* @param rhs The object to which to compare | ||
* @returns A numeric value for which the sign indicates the ordering of this object relative to the other object. | ||
*/ | ||
compare(rhs: T): number; | ||
} | ||
/** @hidden */ | ||
export declare function compare<T extends Comparable<T>>(lhs: T, rhs: T): number; | ||
/** @hidden */ | ||
export declare function comparePossiblyUndefined<T>(compareDefined: (lhs: T, rhs: T) => number, lhs?: T, rhs?: T): number; | ||
@@ -35,0 +36,0 @@ /** @hidden */ |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
@@ -9,3 +9,3 @@ *--------------------------------------------------------------------------------------------*/ | ||
/** | ||
* Basic comparison routine for numbers which treats two numbers as equal if the absolute value of their difference is less than the specified tolerance. | ||
* An [[OrderedComparator]] for numbers that treats two numbers as equal if the absolute value of their difference is less than a specified tolerance. | ||
* @hidden | ||
@@ -32,5 +32,2 @@ */ | ||
/** @hidden */ | ||
function compare(lhs, rhs) { return lhs.compare(rhs); } | ||
exports.compare = compare; | ||
/** @hidden */ | ||
function comparePossiblyUndefined(compareDefined, lhs, rhs) { | ||
@@ -37,0 +34,0 @@ if (undefined === lhs) |
@@ -1,6 +0,17 @@ | ||
/** @module Utils */ | ||
/** @module Collections */ | ||
import { CloneFunction } from "./SortedArray"; | ||
import { OrderedComparator } from "./Compare"; | ||
/** | ||
* Represents an entry in a [[Dictionary]]. | ||
*/ | ||
export interface DictionaryEntry<K, V> { | ||
/** The key used for lookup in the Dictionary. */ | ||
key: K; | ||
/** The value associated with the key in the Dictionary. */ | ||
value: V; | ||
} | ||
/** | ||
* Maintains a mapping of keys to values. | ||
* Unlike the standard Map<K, V>, a Dictionary<K, V> supports custom comparison logic for keys of object type (and for any other type). | ||
* The user supplies a key comparison function to the constructor, which must meet the following criteria given 'lhs' and 'rhs' of type K: | ||
* The user supplies a key comparison function to the constructor, that must meet the following criteria given 'lhs' and 'rhs' of type K: | ||
* - If lhs is equal to rhs, returns 0 | ||
@@ -15,20 +26,19 @@ * - If lhs is less than rhs, returns a negative value | ||
*/ | ||
export declare class Dictionary<K, V> { | ||
export declare class Dictionary<K, V> implements Iterable<DictionaryEntry<K, V>> { | ||
protected _keys: K[]; | ||
protected readonly _compareKeys: (lhs: K, rhs: K) => number; | ||
protected readonly _cloneKey: (key: K) => K; | ||
protected readonly _compareKeys: OrderedComparator<K>; | ||
protected readonly _cloneKey: CloneFunction<K>; | ||
protected _values: V[]; | ||
protected readonly _cloneValue: (src: V) => V; | ||
protected readonly _cloneValue: CloneFunction<V>; | ||
/** | ||
* Construct a new Dictionary<K, V>. | ||
* @param compareKeys A function accepting two values of type K and returning a negative value if lhs < rhs, | ||
* zero if lhs == rhs, and a positive value otherwise. | ||
* @param cloneKey A function that, given a value of type K, returns an equivalent value of type K. | ||
* This function is invoked when a new key is inserted into the dictionary. The default implementation simply returns its input. | ||
* @param cloneValue A function that, given a value of type V, returns an equivalent value of type V. | ||
* This function is invoked when a new value is inserted into the dictionary. The default implementation simply returns its input. | ||
* @param compareKeys The function used to compare keys within the dictionary. | ||
* @param cloneKey The function invoked to clone a key for insertion into the dictionary. The default implementation simply returns its input. | ||
* @param cloneValue The function invoked to clone a value for insertion into the dictionary. The default implementation simply returns its input. | ||
*/ | ||
constructor(compareKeys: (lhs: K, rhs: K) => number, cloneKey?: (src: K) => K, cloneValue?: (src: V) => V); | ||
constructor(compareKeys: OrderedComparator<K>, cloneKey?: CloneFunction<K>, cloneValue?: CloneFunction<V>); | ||
/** The number of entries in the dictionary. */ | ||
readonly length: number; | ||
/** Returns an iterator over the key-value pairs in the Dictionary suitable for use in `for-of` loops. Entries are returned in sorted order by key. */ | ||
[Symbol.iterator](): Iterator<DictionaryEntry<K, V>>; | ||
/** Removes all entries from this dictionary */ | ||
@@ -45,4 +55,5 @@ clear(): void; | ||
* @param key The key to delete | ||
* @returns true if the key was found and deleted. | ||
*/ | ||
delete(key: K): void; | ||
delete(key: K): boolean; | ||
/** | ||
@@ -80,2 +91,6 @@ * Attempts to insert a new entry into the dictionary. If an entry with an equivalent key exists, the dictionary is unmodified. | ||
}; | ||
/** Apply a function to each (key, value) pair in the dictionary, in sorted order. | ||
* @param func The function to be applied. | ||
*/ | ||
forEach(func: (key: K, value: V) => void): void; | ||
/** | ||
@@ -82,0 +97,0 @@ * Computes the position at which the specified key should be inserted to maintain sorted order. |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
*--------------------------------------------------------------------------------------------*/ | ||
/** @module Utils */ | ||
/** @module Collections */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const SortedArray_1 = require("./SortedArray"); | ||
class DictionaryIterator { | ||
constructor(keys, values) { | ||
this._curIndex = -1; | ||
this._keys = keys; | ||
this._values = values; | ||
} | ||
next() { | ||
if (++this._curIndex >= this._keys.length) { | ||
// The ECMAScript spec states that value=undefined is valid if done=true. The TypeScript interface violates the spec hence the cast to any and back below. | ||
return { done: true }; | ||
} | ||
else { | ||
return { | ||
value: { | ||
key: this._keys[this._curIndex], | ||
value: this._values[this._curIndex], | ||
}, | ||
done: false, | ||
}; | ||
} | ||
} | ||
} | ||
/** | ||
* Maintains a mapping of keys to values. | ||
* Unlike the standard Map<K, V>, a Dictionary<K, V> supports custom comparison logic for keys of object type (and for any other type). | ||
* The user supplies a key comparison function to the constructor, which must meet the following criteria given 'lhs' and 'rhs' of type K: | ||
* The user supplies a key comparison function to the constructor, that must meet the following criteria given 'lhs' and 'rhs' of type K: | ||
* - If lhs is equal to rhs, returns 0 | ||
@@ -25,10 +47,7 @@ * - If lhs is less than rhs, returns a negative value | ||
* Construct a new Dictionary<K, V>. | ||
* @param compareKeys A function accepting two values of type K and returning a negative value if lhs < rhs, | ||
* zero if lhs == rhs, and a positive value otherwise. | ||
* @param cloneKey A function that, given a value of type K, returns an equivalent value of type K. | ||
* This function is invoked when a new key is inserted into the dictionary. The default implementation simply returns its input. | ||
* @param cloneValue A function that, given a value of type V, returns an equivalent value of type V. | ||
* This function is invoked when a new value is inserted into the dictionary. The default implementation simply returns its input. | ||
* @param compareKeys The function used to compare keys within the dictionary. | ||
* @param cloneKey The function invoked to clone a key for insertion into the dictionary. The default implementation simply returns its input. | ||
* @param cloneValue The function invoked to clone a value for insertion into the dictionary. The default implementation simply returns its input. | ||
*/ | ||
constructor(compareKeys, cloneKey = SortedArray_1.defaultClone, cloneValue = SortedArray_1.defaultClone) { | ||
constructor(compareKeys, cloneKey = SortedArray_1.shallowClone, cloneValue = SortedArray_1.shallowClone) { | ||
this._keys = []; | ||
@@ -42,2 +61,4 @@ this._values = []; | ||
get length() { return this._keys.length; } | ||
/** Returns an iterator over the key-value pairs in the Dictionary suitable for use in `for-of` loops. Entries are returned in sorted order by key. */ | ||
[Symbol.iterator]() { return new DictionaryIterator(this._keys, this._values); } | ||
/** Removes all entries from this dictionary */ | ||
@@ -60,2 +81,3 @@ clear() { | ||
* @param key The key to delete | ||
* @returns true if the key was found and deleted. | ||
*/ | ||
@@ -67,3 +89,7 @@ delete(key) { | ||
this._keys.splice(bound.index, 1); | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
@@ -123,2 +149,9 @@ /** | ||
} | ||
/** Apply a function to each (key, value) pair in the dictionary, in sorted order. | ||
* @param func The function to be applied. | ||
*/ | ||
forEach(func) { | ||
for (let i = 0; i < this.length; i++) | ||
func(this._keys[i], this._values[i]); | ||
} | ||
/** | ||
@@ -125,0 +158,0 @@ * Computes the position at which the specified key should be inserted to maintain sorted order. |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
@@ -5,0 +5,0 @@ *--------------------------------------------------------------------------------------------*/ |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
@@ -5,0 +5,0 @@ *--------------------------------------------------------------------------------------------*/ |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
@@ -5,0 +5,0 @@ *--------------------------------------------------------------------------------------------*/ |
@@ -60,9 +60,18 @@ /** @module Ids */ | ||
function fromUint32Pair(lowBytes: number, highBytes: number): Id64String; | ||
/** Extract an unsigned 32-bit integer from the lower 4 bytes of an Id64String. | ||
* @returns the unsigned 32-bit integer value stored in the id's lower 4 bytes | ||
/** @hidden */ | ||
function isValidUint32Pair(lowBytes: number, highBytes: number): boolean; | ||
/** Represents an unsigned 64-bit integer as a pair of unsigned 32-bit integers. | ||
* @see [[Id64.getUint32Pair]] | ||
*/ | ||
interface Uint32Pair { | ||
/** The lower 4 bytes of the 64-bit integer. */ | ||
lower: number; | ||
/** The upper 4 bytes of the 64-bit integer. */ | ||
upper: number; | ||
} | ||
/** Convert an Id64String to a 64-bit unsigned integer represented as a pair of unsigned 32-bit integers. */ | ||
function getUint32Pair(id: Id64String): Uint32Pair; | ||
/** Extract an unsigned 32-bit integer from the lower 4 bytes of an Id64String. */ | ||
function getLowerUint32(id: Id64String): number; | ||
/** Extract an unsigned 32-bit integer from the upper 4 bytes of an Id64String. | ||
* @returns the unsigned 32-bit integer value stored in the id's upper 4 bytes | ||
*/ | ||
/** Extract an unsigned 32-bit integer from the upper 4 bytes of an Id64String. */ | ||
function getUpperUint32(id: Id64String): number; | ||
@@ -114,2 +123,52 @@ /** Convert an [[Id64Arg]] into an [[Id64Set]]. | ||
function isInvalid(id: Id64String): boolean; | ||
/** A specialized replacement for Set<Id64String> optimized for performance-critical code which represents large sets of 64-bit IDs as pairs of | ||
* 32-bit integers. | ||
* The internal representation is a Map<number, Set<number>> where the Map key is the upper 4 bytes of the IDs and the Set elements are the lower 4 bytes of the IDs. | ||
* Because the upper 4 bytes store the 24-bit briefcase ID plus the upper 8 bits of the local ID, there will be a very small distribution of unique Map keys. | ||
* To further optimize this data type, the following assumptions are made regarding the { lower, upper } inputs, and no validation is performed to confirm them: | ||
* - The inputs are unsigned 32-bit integers; | ||
* - The inputs represent a valid Id64String (e.g., local ID is not zero). | ||
* @see [[Id64.Uint32Map]] for a similarly-optimized replacement for Map<Id64String, T> | ||
*/ | ||
class Uint32Set { | ||
protected readonly _map: Map<number, Set<number>>; | ||
/** Remove all contents of this set. */ | ||
clear(): void; | ||
/** Add an Id to the set. */ | ||
addId(id: Id64String): void; | ||
/** Returns true if the set contains the specified Id. */ | ||
hasId(id: Id64String): boolean; | ||
/** Add an Id to the set. */ | ||
add(low: number, high: number): void; | ||
/** Returns true if the set contains the specified Id. */ | ||
has(low: number, high: number): boolean; | ||
/** Returns true if the set contains no Ids. */ | ||
readonly isEmpty: boolean; | ||
/** Returns the number of Ids contained in the set. */ | ||
readonly size: number; | ||
/** Populates and returns an array of all Ids contained in the set. */ | ||
toId64Array(): Id64Array; | ||
/** Populates and returns a set of all Ids contained in the set. */ | ||
toId64Set(): Id64Set; | ||
} | ||
/** A specialized replacement for Map<Id64String, T> optimized for performance-critical code. | ||
* @see [[Id64.Uint32Set]] for implementation details. | ||
*/ | ||
class Uint32Map<T> { | ||
protected readonly _map: Map<number, Map<number, T>>; | ||
/** Remove all entries from the map. */ | ||
clear(): void; | ||
/** Find an entry in the map by Id. */ | ||
getById(id: Id64String): T | undefined; | ||
/** Set an entry in the map by Id. */ | ||
setById(id: Id64String, value: T): void; | ||
/** Set an entry in the map by Id components. */ | ||
set(low: number, high: number, value: T): void; | ||
/** Get an entry from the map by Id components. */ | ||
get(low: number, high: number): T | undefined; | ||
/** Returns true if the map contains no entries. */ | ||
readonly isEmpty: boolean; | ||
/** Returns the number of entries in the map. */ | ||
readonly size: number; | ||
} | ||
} | ||
@@ -116,0 +175,0 @@ /** |
218
lib/Id.js
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
@@ -106,2 +106,16 @@ *--------------------------------------------------------------------------------------------*/ | ||
Id64.fromString = fromString; | ||
// Used when constructing local ID portion of Id64String. Performance optimization. | ||
const _localIdPrefixByLocalIdLength = [ | ||
"0000000000", | ||
"000000000", | ||
"00000000", | ||
"0000000", | ||
"000000", | ||
"00000", | ||
"0000", | ||
"000", | ||
"00", | ||
"0", | ||
"", | ||
]; | ||
/** Produce an Id string from a local and briefcase Id. | ||
@@ -122,5 +136,45 @@ * @param localId The non-zero local Id as an unsigned 40-bit integer. | ||
const lowStr = localId.toString(16); | ||
return "0x" + ((briefcaseId === 0) ? lowStr : (briefcaseId.toString(16) + ("0000000000" + lowStr).substr(-10))); | ||
return "0x" + ((briefcaseId === 0) ? lowStr : (briefcaseId.toString(16) + (_localIdPrefixByLocalIdLength[lowStr.length] + lowStr))); | ||
} | ||
Id64.fromLocalAndBriefcaseIds = fromLocalAndBriefcaseIds; | ||
// Used as a buffer when converting a pair of 32-bit integers to an Id64String. Significant performance optimization. | ||
const _scratchCharCodes = [ | ||
0x30, | ||
0x78, | ||
0x30, | ||
0x30, | ||
0x30, | ||
0x30, | ||
0x30, | ||
0x30, | ||
0x30, | ||
0x30, | ||
0x30, | ||
0x30, | ||
0x30, | ||
0x30, | ||
0x30, | ||
0x30, | ||
0x30, | ||
0x30, | ||
]; | ||
// Convert 4-bit unsigned integer to char code representing lower-case hexadecimal digit. | ||
function uint4ToCharCode(uint4) { | ||
return uint4 + (uint4 < 10 ? 0x30 : 0x57); | ||
} | ||
// Convert char code representing lower-case hexadecimal digit to 4-bit unsigned integer. | ||
function charCodeToUint4(char) { | ||
return char - (char >= 0x57 ? 0x57 : 0x30); | ||
} | ||
// Convert a substring to a uint32. This is twice as fast as using Number.parseInt(). | ||
function substringToUint32(id, start, end) { | ||
let uint32 = 0; | ||
for (let i = start; i < end; i++) { | ||
const uint4 = charCodeToUint4(id.charCodeAt(i)); | ||
const shift = (end - i - 1) << 2; | ||
const mask = uint4 << shift; | ||
uint32 = (uint32 | mask) >>> 0; // >>> 0 to force unsigned because javascript | ||
} | ||
return uint32; | ||
} | ||
/** Create an Id64String from a pair of unsigned 32-bit integers. | ||
@@ -136,31 +190,55 @@ * @param lowBytes The lower 4 bytes of the Id | ||
const localId = localIdLow + localIdHigh; // aka localIdLow | localIdHigh | ||
const briefcaseId = (highBytes & 0xffffff00) >>> 8; | ||
return Id64.fromLocalAndBriefcaseIds(localId, briefcaseId); | ||
if (0 === localId) | ||
return Id64.invalid; | ||
// Need to omit or preserve leading zeroes... | ||
const buffer = _scratchCharCodes; | ||
let index = 2; | ||
for (let i = 7; i >= 0; i--) { | ||
const shift = i << 2; | ||
const mask = 0xf << shift; | ||
const uint4 = (highBytes & mask) >>> shift; | ||
if (index > 2 || 0 !== uint4) | ||
buffer[index++] = uint4ToCharCode(uint4); | ||
} | ||
for (let i = 7; i >= 0; i--) { | ||
const shift = i << 2; | ||
const mask = 0xf << shift; | ||
const uint4 = (lowBytes & mask) >>> shift; | ||
if (index > 2 || 0 !== uint4) | ||
buffer[index++] = uint4ToCharCode(uint4); | ||
} | ||
if (buffer.length !== index) | ||
buffer.length = index; | ||
return String.fromCharCode(..._scratchCharCodes); | ||
} | ||
Id64.fromUint32Pair = fromUint32Pair; | ||
/** Extract an unsigned 32-bit integer from the lower 4 bytes of an Id64String. | ||
* @returns the unsigned 32-bit integer value stored in the id's lower 4 bytes | ||
*/ | ||
/** @hidden */ | ||
function isValidUint32Pair(lowBytes, highBytes) { | ||
// Detect local ID of zero | ||
return 0 !== lowBytes || 0 !== (highBytes & 0x000000ff); | ||
} | ||
Id64.isValidUint32Pair = isValidUint32Pair; | ||
/** Convert an Id64String to a 64-bit unsigned integer represented as a pair of unsigned 32-bit integers. */ | ||
function getUint32Pair(id) { | ||
return { | ||
lower: getLowerUint32(id), | ||
upper: getUpperUint32(id), | ||
}; | ||
} | ||
Id64.getUint32Pair = getUint32Pair; | ||
/** Extract an unsigned 32-bit integer from the lower 4 bytes of an Id64String. */ | ||
function getLowerUint32(id) { | ||
if (isInvalid(id)) | ||
return 0; | ||
const str = id.toString(); | ||
let start = 2; | ||
const len = str.length; | ||
if (len > 10) | ||
start = len - 8; | ||
return toHex(str.slice(start)); | ||
const end = id.length; | ||
const start = end > 10 ? end - 8 : 2; | ||
return substringToUint32(id, start, end); | ||
} | ||
Id64.getLowerUint32 = getLowerUint32; | ||
/** Extract an unsigned 32-bit integer from the upper 4 bytes of an Id64String. | ||
* @returns the unsigned 32-bit integer value stored in the id's upper 4 bytes | ||
*/ | ||
/** Extract an unsigned 32-bit integer from the upper 4 bytes of an Id64String. */ | ||
function getUpperUint32(id) { | ||
if (isInvalid(id)) | ||
return 0; | ||
const len = id.length; | ||
if (len <= 10) | ||
if (len <= 10 || isInvalid(id)) | ||
return 0; | ||
const start = len - 8; | ||
return toHex(id.slice(2, start)); | ||
return substringToUint32(id, 2, len - 8); | ||
} | ||
@@ -268,2 +346,100 @@ Id64.getUpperUint32 = getUpperUint32; | ||
Id64.isInvalid = isInvalid; | ||
/** A specialized replacement for Set<Id64String> optimized for performance-critical code which represents large sets of 64-bit IDs as pairs of | ||
* 32-bit integers. | ||
* The internal representation is a Map<number, Set<number>> where the Map key is the upper 4 bytes of the IDs and the Set elements are the lower 4 bytes of the IDs. | ||
* Because the upper 4 bytes store the 24-bit briefcase ID plus the upper 8 bits of the local ID, there will be a very small distribution of unique Map keys. | ||
* To further optimize this data type, the following assumptions are made regarding the { lower, upper } inputs, and no validation is performed to confirm them: | ||
* - The inputs are unsigned 32-bit integers; | ||
* - The inputs represent a valid Id64String (e.g., local ID is not zero). | ||
* @see [[Id64.Uint32Map]] for a similarly-optimized replacement for Map<Id64String, T> | ||
*/ | ||
class Uint32Set { | ||
constructor() { | ||
this._map = new Map(); | ||
} | ||
/** Remove all contents of this set. */ | ||
clear() { this._map.clear(); } | ||
/** Add an Id to the set. */ | ||
addId(id) { this.add(Id64.getLowerUint32(id), Id64.getUpperUint32(id)); } | ||
/** Returns true if the set contains the specified Id. */ | ||
hasId(id) { return this.has(Id64.getLowerUint32(id), Id64.getUpperUint32(id)); } | ||
/** Add an Id to the set. */ | ||
add(low, high) { | ||
let set = this._map.get(high); | ||
if (undefined === set) { | ||
set = new Set(); | ||
this._map.set(high, set); | ||
} | ||
set.add(low); | ||
} | ||
/** Returns true if the set contains the specified Id. */ | ||
has(low, high) { | ||
const set = this._map.get(high); | ||
return undefined !== set && set.has(low); | ||
} | ||
/** Returns true if the set contains no Ids. */ | ||
get isEmpty() { return 0 === this._map.size; } | ||
/** Returns the number of Ids contained in the set. */ | ||
get size() { | ||
let size = 0; | ||
for (const entry of this._map) | ||
size += entry[1].size; | ||
return size; | ||
} | ||
/** Populates and returns an array of all Ids contained in the set. */ | ||
toId64Array() { | ||
const ids = []; | ||
for (const entry of this._map) | ||
for (const low of entry[1]) | ||
ids.push(Id64.fromUint32Pair(low, entry[0])); | ||
return ids; | ||
} | ||
/** Populates and returns a set of all Ids contained in the set. */ | ||
toId64Set() { | ||
const ids = new Set(); | ||
for (const entry of this._map) | ||
for (const low of entry[1]) | ||
ids.add(Id64.fromUint32Pair(low, entry[0])); | ||
return ids; | ||
} | ||
} | ||
Id64.Uint32Set = Uint32Set; | ||
/** A specialized replacement for Map<Id64String, T> optimized for performance-critical code. | ||
* @see [[Id64.Uint32Set]] for implementation details. | ||
*/ | ||
class Uint32Map { | ||
constructor() { | ||
this._map = new Map(); | ||
} | ||
/** Remove all entries from the map. */ | ||
clear() { this._map.clear(); } | ||
/** Find an entry in the map by Id. */ | ||
getById(id) { return this.get(Id64.getLowerUint32(id), Id64.getUpperUint32(id)); } | ||
/** Set an entry in the map by Id. */ | ||
setById(id, value) { this.set(Id64.getLowerUint32(id), Id64.getUpperUint32(id), value); } | ||
/** Set an entry in the map by Id components. */ | ||
set(low, high, value) { | ||
let map = this._map.get(high); | ||
if (undefined === map) { | ||
map = new Map(); | ||
this._map.set(high, map); | ||
} | ||
map.set(low, value); | ||
} | ||
/** Get an entry from the map by Id components. */ | ||
get(low, high) { | ||
const map = this._map.get(high); | ||
return undefined !== map ? map.get(low) : undefined; | ||
} | ||
/** Returns true if the map contains no entries. */ | ||
get isEmpty() { return 0 === this._map.size; } | ||
/** Returns the number of entries in the map. */ | ||
get size() { | ||
let size = 0; | ||
for (const entry of this._map) | ||
size += entry[1].size; | ||
return size; | ||
} | ||
} | ||
Id64.Uint32Map = Uint32Map; | ||
})(Id64 = exports.Id64 || (exports.Id64 = {})); | ||
@@ -270,0 +446,0 @@ /** |
@@ -1,2 +0,4 @@ | ||
/** @module Utils */ | ||
/** @module Collections */ | ||
import { CloneFunction } from "./SortedArray"; | ||
import { OrderedComparator } from "./Compare"; | ||
/** Associates a value of type T with an index representing its insertion order in an IndexMap<T> */ | ||
@@ -15,15 +17,12 @@ export declare class IndexedValue<T> { | ||
protected _array: Array<IndexedValue<T>>; | ||
protected readonly _compareValues: (lhs: T, rhs: T) => number; | ||
protected readonly _clone: (src: T) => T; | ||
protected readonly _compareValues: OrderedComparator<T>; | ||
protected readonly _clone: CloneFunction<T>; | ||
protected readonly _maximumSize: number; | ||
/** | ||
* Construct a new IndexMap<T>. | ||
* @param compare A function accepting two values of type T and returning a negative value if lhs < rhs, | ||
* zero if lhs == rhs, and a positive value otherwise. | ||
* @param compare The function used to compare elements within the map. | ||
* @param maximumSize The maximum number of elements permitted in the IndexMap. The maximum index of an element is maximumSize-1. | ||
* @param clone A function that, given a value of type T, returns an equivalent value of type T. | ||
* This function is invoked when a new element is inserted into the array. | ||
* The default implementation simply returns its input. | ||
* @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input. | ||
*/ | ||
constructor(compare: (lhs: T, rhs: T) => number, maximumSize?: number, clone?: (src: T) => T); | ||
constructor(compare: OrderedComparator<T>, maximumSize?: number, clone?: CloneFunction<T>); | ||
/** The number of elements in the map. */ | ||
@@ -30,0 +29,0 @@ readonly length: number; |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
*--------------------------------------------------------------------------------------------*/ | ||
/** @module Utils */ | ||
/** @module Collections */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -25,10 +25,7 @@ const SortedArray_1 = require("./SortedArray"); | ||
* Construct a new IndexMap<T>. | ||
* @param compare A function accepting two values of type T and returning a negative value if lhs < rhs, | ||
* zero if lhs == rhs, and a positive value otherwise. | ||
* @param compare The function used to compare elements within the map. | ||
* @param maximumSize The maximum number of elements permitted in the IndexMap. The maximum index of an element is maximumSize-1. | ||
* @param clone A function that, given a value of type T, returns an equivalent value of type T. | ||
* This function is invoked when a new element is inserted into the array. | ||
* The default implementation simply returns its input. | ||
* @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input. | ||
*/ | ||
constructor(compare, maximumSize = Number.MAX_SAFE_INTEGER, clone = SortedArray_1.defaultClone) { | ||
constructor(compare, maximumSize = Number.MAX_SAFE_INTEGER, clone = SortedArray_1.shallowClone) { | ||
this._array = []; | ||
@@ -35,0 +32,0 @@ this._compareValues = compare; |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
@@ -5,0 +5,0 @@ *--------------------------------------------------------------------------------------------*/ |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
@@ -5,0 +5,0 @@ *--------------------------------------------------------------------------------------------*/ |
@@ -1,2 +0,2 @@ | ||
/** @module Utils */ | ||
/** @module Collections */ | ||
/** An entry holds the key and value, and pointers to any older and newer entries. */ | ||
@@ -3,0 +3,0 @@ export declare class Entry<K, V> { |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
*--------------------------------------------------------------------------------------------*/ | ||
/** @module Utils */ | ||
/** @module Collections */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -8,0 +8,0 @@ /* |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
@@ -5,0 +5,0 @@ *--------------------------------------------------------------------------------------------*/ |
@@ -1,9 +0,15 @@ | ||
/** @module Utils */ | ||
/** @module Collections */ | ||
import { OrderedComparator } from "./Compare"; | ||
/** | ||
* An identity function which given a value of type T, returns the same value. | ||
* Useful as a default argument for functions which can alternatively accept custom logic for cloning values of object type. | ||
* A function that, given a value of type T, returns a copy of that value. Such functions are used by various collection classes in the iModel.js library. | ||
* It is up to the function to decide how deeply or shallowly the value is cloned. For example, [[shallowClone]] simply returns the input. | ||
*/ | ||
export declare type CloneFunction<T> = (value: T) => T; | ||
/** | ||
* A [[CloneFunction]] that, given a value of type T, returns the same value. | ||
* Useful as a default argument for functions that can alternatively accept custom logic for cloning values of object type. | ||
* @param value The value to clone. | ||
* @returns the input value. | ||
*/ | ||
export declare function defaultClone<T>(value: T): T; | ||
export declare function shallowClone<T>(value: T): T; | ||
/** | ||
@@ -13,7 +19,6 @@ * Given a sorted array, computes the position at which the specified value should be inserted into the array so that the array remains sorted. | ||
* @param list An array of U already sorted according to the comparison criterion. | ||
* @param compare A function accepting a value of type T and a value of type U and returning a negative value if lhs < rhs, | ||
* zero if lhs == rhs, and a positive value otherwise. | ||
* @param compare The function used to compare the value with elements in `list`. | ||
* @returns an object with 'index' corresponding to the computed position and 'equal' set to true if an equivalent element already exists at that index. | ||
*/ | ||
export declare function lowerBound<T, U = T>(value: T, list: U[], compare: (lhs: T, rhs: U) => number): { | ||
export declare function lowerBound<T, U = T>(value: T, list: U[], compare: OrderedComparator<T, U>): { | ||
index: number; | ||
@@ -25,3 +30,3 @@ equal: boolean; | ||
* by the user. | ||
* By default, only unique elements are permitted; attempting to insert a new element which compares | ||
* By default, only unique elements are permitted; attempting to insert a new element that compares | ||
* as equal to an element already in the array will not modify the contents of the array. | ||
@@ -47,21 +52,22 @@ * | ||
*/ | ||
export declare class SortedArray<T> { | ||
export declare class SortedArray<T> implements Iterable<T> { | ||
protected _array: T[]; | ||
protected readonly _compare: (lhs: T, rhs: T) => number; | ||
protected readonly _clone: (src: T) => T; | ||
protected readonly _compare: OrderedComparator<T>; | ||
protected readonly _clone: CloneFunction<T>; | ||
protected readonly _allowDuplicates: boolean; | ||
/** | ||
* Construct a new SortedArray<T>. | ||
* @param compare A function accepting two values of type T and returning a negative value if lhs < rhs, | ||
* zero if lhs == rhs, and a positive value otherwise. | ||
* @param compare The function used to compare elements within the array. | ||
* @param allowDuplicates If true, multiple values comparing equal may exist in the array. | ||
* @param clone A function that, given a value of type T, returns an equivalent value of type T. | ||
* This function is invoked when a new element is inserted into the array. | ||
* The default implementation simply returns its input. | ||
* @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input. | ||
*/ | ||
constructor(compare: (lhs: T, rhs: T) => number, allowDuplicates?: boolean, clone?: (src: T) => T); | ||
constructor(compare: OrderedComparator<T>, allowDuplicates?: boolean, clone?: CloneFunction<T>); | ||
/** The number of elements in the array */ | ||
readonly length: number; | ||
/** Returns true if the array contains no elements. */ | ||
readonly isEmpty: boolean; | ||
/** Clears the contents of the sorted array. */ | ||
clear(): void; | ||
/** Returns an iterator over the contents of the array in sorted order, suitable for use in `for-of` loops. */ | ||
[Symbol.iterator](): Iterator<T>; | ||
/** Extracts the sorted array as a T[] and empties the contents of this SortedArray. | ||
@@ -88,2 +94,8 @@ * @returns the contents of this SortedArray as a T[]. | ||
/** | ||
* Removes the first occurrence of a value comparing equal to the specified value from the array. | ||
* @param value The value of the element to delete | ||
* @returns the index of the deleted value, or -1 if no such element exists. | ||
*/ | ||
remove(value: T): number; | ||
/** | ||
* Looks up the index of an element comparing equal to the specified value using binary search. | ||
@@ -95,5 +107,11 @@ * @param value The value to search for | ||
/** | ||
* Returns true if this array contains at least one value comparing equal to the specified value. | ||
* @param value The value to search for | ||
* @returns true if an equivalent element exists in the array. | ||
*/ | ||
contains(value: T): boolean; | ||
/** | ||
* Looks up an element comparing equal to the specified value using binary search. | ||
* @param value The value to search for | ||
* @returns the first equivalent element in the array, or -1 if no such element exists. | ||
* @returns the first equivalent element in the array, or undefined if no such element exists. | ||
*/ | ||
@@ -107,2 +125,6 @@ findEqual(value: T): T | undefined; | ||
get(index: number): T | undefined; | ||
/** Apply a function to each element in the array, in sorted order. | ||
* @param func The function to be applied. | ||
*/ | ||
forEach(func: (value: T) => void): void; | ||
/** | ||
@@ -109,0 +131,0 @@ * Computes the position at which the specified value should be inserted to maintain sorted order. |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
*--------------------------------------------------------------------------------------------*/ | ||
/** @module Utils */ | ||
/** @module Collections */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* An identity function which given a value of type T, returns the same value. | ||
* Useful as a default argument for functions which can alternatively accept custom logic for cloning values of object type. | ||
* A [[CloneFunction]] that, given a value of type T, returns the same value. | ||
* Useful as a default argument for functions that can alternatively accept custom logic for cloning values of object type. | ||
* @param value The value to clone. | ||
* @returns the input value. | ||
*/ | ||
function defaultClone(value) { return value; } | ||
exports.defaultClone = defaultClone; | ||
function shallowClone(value) { return value; } | ||
exports.shallowClone = shallowClone; | ||
/** | ||
@@ -20,4 +20,3 @@ * Given a sorted array, computes the position at which the specified value should be inserted into the array so that the array remains sorted. | ||
* @param list An array of U already sorted according to the comparison criterion. | ||
* @param compare A function accepting a value of type T and a value of type U and returning a negative value if lhs < rhs, | ||
* zero if lhs == rhs, and a positive value otherwise. | ||
* @param compare The function used to compare the value with elements in `list`. | ||
* @returns an object with 'index' corresponding to the computed position and 'equal' set to true if an equivalent element already exists at that index. | ||
@@ -44,3 +43,3 @@ */ | ||
* by the user. | ||
* By default, only unique elements are permitted; attempting to insert a new element which compares | ||
* By default, only unique elements are permitted; attempting to insert a new element that compares | ||
* as equal to an element already in the array will not modify the contents of the array. | ||
@@ -69,10 +68,7 @@ * | ||
* Construct a new SortedArray<T>. | ||
* @param compare A function accepting two values of type T and returning a negative value if lhs < rhs, | ||
* zero if lhs == rhs, and a positive value otherwise. | ||
* @param compare The function used to compare elements within the array. | ||
* @param allowDuplicates If true, multiple values comparing equal may exist in the array. | ||
* @param clone A function that, given a value of type T, returns an equivalent value of type T. | ||
* This function is invoked when a new element is inserted into the array. | ||
* The default implementation simply returns its input. | ||
* @param clone The function invoked to clone a new element for insertion into the array. The default implementation simply returns its input. | ||
*/ | ||
constructor(compare, allowDuplicates = false, clone = defaultClone) { | ||
constructor(compare, allowDuplicates = false, clone = shallowClone) { | ||
this._array = []; | ||
@@ -85,4 +81,8 @@ this._compare = compare; | ||
get length() { return this._array.length; } | ||
/** Returns true if the array contains no elements. */ | ||
get isEmpty() { return 0 === this.length; } | ||
/** Clears the contents of the sorted array. */ | ||
clear() { this._array = []; } | ||
clear() { this._array.length = 0; } | ||
/** Returns an iterator over the contents of the array in sorted order, suitable for use in `for-of` loops. */ | ||
[Symbol.iterator]() { return this._array[Symbol.iterator](); } | ||
/** Extracts the sorted array as a T[] and empties the contents of this SortedArray. | ||
@@ -93,3 +93,3 @@ * @returns the contents of this SortedArray as a T[]. | ||
const result = this._array; | ||
this.clear(); | ||
this._array = []; | ||
return result; | ||
@@ -121,2 +121,17 @@ } | ||
/** | ||
* Removes the first occurrence of a value comparing equal to the specified value from the array. | ||
* @param value The value of the element to delete | ||
* @returns the index of the deleted value, or -1 if no such element exists. | ||
*/ | ||
remove(value) { | ||
const bound = this.lowerBound(value); | ||
if (bound.equal) { | ||
this._array.splice(bound.index, 1); | ||
return bound.index; | ||
} | ||
else { | ||
return -1; | ||
} | ||
} | ||
/** | ||
* Looks up the index of an element comparing equal to the specified value using binary search. | ||
@@ -131,5 +146,13 @@ * @param value The value to search for | ||
/** | ||
* Returns true if this array contains at least one value comparing equal to the specified value. | ||
* @param value The value to search for | ||
* @returns true if an equivalent element exists in the array. | ||
*/ | ||
contains(value) { | ||
return -1 !== this.indexOf(value); | ||
} | ||
/** | ||
* Looks up an element comparing equal to the specified value using binary search. | ||
* @param value The value to search for | ||
* @returns the first equivalent element in the array, or -1 if no such element exists. | ||
* @returns the first equivalent element in the array, or undefined if no such element exists. | ||
*/ | ||
@@ -146,2 +169,9 @@ findEqual(value) { | ||
get(index) { return index < this.length ? this._array[index] : undefined; } | ||
/** Apply a function to each element in the array, in sorted order. | ||
* @param func The function to be applied. | ||
*/ | ||
forEach(func) { | ||
for (let i = 0; i < this.length; i++) | ||
func(this._array[i]); | ||
} | ||
/** | ||
@@ -148,0 +178,0 @@ * Computes the position at which the specified value should be inserted to maintain sorted order. |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
@@ -5,0 +5,0 @@ *--------------------------------------------------------------------------------------------*/ |
"use strict"; | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved. | ||
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license terms. | ||
@@ -5,0 +5,0 @@ *--------------------------------------------------------------------------------------------*/ |
# MIT License | ||
Copyright © 2018 Bentley Systems, Incorporated. All rights reserved. | ||
Copyright © 2019 Bentley Systems, Incorporated. All rights reserved. | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
{ | ||
"name": "@bentley/bentleyjs-core", | ||
"version": "0.171.0", | ||
"version": "0.187.0", | ||
"description": "Bentley JavaScript core components", | ||
@@ -13,3 +13,3 @@ "main": "lib/bentleyjs-core.js", | ||
"scripts": { | ||
"build": "tsc 1>&2", | ||
"build": "tsc 1>&2 && npm run webpackModule-dev", | ||
"clean": "rimraf lib package-deps.json", | ||
@@ -20,3 +20,5 @@ "test": "node ./node_modules/@bentley/build-tools/scripts/test.js", | ||
"cover:docs": "node ./node_modules/@bentley/build-tools/scripts/docscoverage.js", | ||
"lint": "tslint --project . 1>&2" | ||
"lint": "tslint --project . 1>&2", | ||
"webpackModule-dev": "make-dir ./lib/module/dev/ && webpack --config ./node_modules/@bentley/webpack-tools/modules/webpackModule.config.js --env.entry=./lib/bentleyjs-core.js --env.bundlename=bentleyjs-core --json >./lib/module/dev/webpackStats.json", | ||
"webpackModule-prod": "webpack --config ./node_modules/@bentley/webpack-tools/modules/webpackModule.config.js --env.entry=./lib/bentleyjs-core.js --env.bundlename=bentleyjs-core --env.prod" | ||
}, | ||
@@ -33,3 +35,4 @@ "keywords": [ | ||
"devDependencies": { | ||
"@bentley/build-tools": "0.171.0", | ||
"@bentley/build-tools": "0.187.0", | ||
"@bentley/webpack-tools": "0.187.0", | ||
"@types/chai": "^4.1.4", | ||
@@ -39,2 +42,3 @@ "@types/mocha": "^5.2.5", | ||
"chai": "^4.1.2", | ||
"make-dir-cli": "^1.0.0", | ||
"mocha": "^5.2.0", | ||
@@ -48,3 +52,6 @@ "rimraf": "^2.6.2", | ||
"nyc": "^13.0.1", | ||
"source-map-support": "^0.5.6" | ||
"source-map-loader": "^0.2.3", | ||
"source-map-support": "^0.5.6", | ||
"webpack": "^4.20.2", | ||
"webpack-cli": "^3.1.0" | ||
}, | ||
@@ -51,0 +58,0 @@ "nyc": { |
# @bentley/bentleyjs-core | ||
Copyright © 2018 Bentley Systems, Incorporated. All rights reserved. | ||
Copyright © 2019 Bentley Systems, Incorporated. All rights reserved. | ||
@@ -5,0 +5,0 @@ ## Description |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
467780
52
9119
19