fix dict
This commit is contained in:
@@ -6,10 +6,15 @@ export type Dictionary<K, V> = {
|
||||
setQueue: Array<[K, V]>;
|
||||
};
|
||||
|
||||
export function createDictionary<K, V>(): Dictionary<K, V> {
|
||||
export function createDictionary<K, V>(
|
||||
iterable?: Iterable<[K, V]>,
|
||||
): Dictionary<K, V> {
|
||||
const entries = iterable ? [...iterable] : [];
|
||||
const indices = new Map(entries.map(([k], i) => [k, i]));
|
||||
|
||||
return {
|
||||
entries: [],
|
||||
indices: new Map(),
|
||||
entries,
|
||||
indices,
|
||||
isIterating: false,
|
||||
deleteQueue: [],
|
||||
setQueue: [],
|
||||
@@ -46,8 +51,8 @@ export function setEntry<K, V>(
|
||||
): void {
|
||||
const index = dict.indices.get(key);
|
||||
if (index === undefined) {
|
||||
dict.entries.push([key, value]);
|
||||
dict.indices.set(key, dict.entries.length);
|
||||
dict.entries.push([key, value]);
|
||||
} else {
|
||||
dict.entries[index][1] = value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user