BREAKING CHANGE(core): refactored ObjectMap and introduced concat feature
This commit is contained in:
@ -10,8 +10,14 @@ export class FastMap<T> {
|
||||
return this.mapObject[keyArg] ? false : true;
|
||||
}
|
||||
|
||||
public addToMap(keyArg: string, objectArg: T): boolean {
|
||||
if (this.isUniqueKey(keyArg)) {
|
||||
public addToMap(
|
||||
keyArg: string,
|
||||
objectArg: T,
|
||||
optionsArg?: {
|
||||
force: boolean;
|
||||
}
|
||||
): boolean {
|
||||
if (this.isUniqueKey(keyArg) || (optionsArg && optionsArg.force)) {
|
||||
this.mapObject[keyArg] = objectArg;
|
||||
return true;
|
||||
} else {
|
||||
@ -32,9 +38,9 @@ export class FastMap<T> {
|
||||
public getKeys() {
|
||||
const keys: string[] = [];
|
||||
for (const keyArg in this.mapObject) {
|
||||
if (this.mapObject[keyArg]) {
|
||||
keys.push(keyArg);
|
||||
}
|
||||
if (this.mapObject[keyArg]) {
|
||||
keys.push(keyArg);
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
@ -42,4 +48,35 @@ export class FastMap<T> {
|
||||
public clean() {
|
||||
this.mapObject = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a new Objectmap that includes
|
||||
*/
|
||||
public concat(fastMapArg: FastMap<T>) {
|
||||
const concatedFastmap = new FastMap<T>();
|
||||
for (const key of this.getKeys()) {
|
||||
concatedFastmap.addToMap(key, this.getByKey(key));
|
||||
}
|
||||
|
||||
for (const key of fastMapArg.getKeys()) {
|
||||
concatedFastmap.addToMap(key, fastMapArg.getByKey(key), {
|
||||
force: true
|
||||
});
|
||||
}
|
||||
|
||||
return concatedFastmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* tries to merge another Objectmap
|
||||
* Note: uniqueKeyCollisions will cause overwrite
|
||||
* @param objectMapArg
|
||||
*/
|
||||
public addAllFromOther(fastMapArg: FastMap<T>) {
|
||||
for (const key of fastMapArg.getKeys()) {
|
||||
this.addToMap(key, fastMapArg.getByKey(key), {
|
||||
force: true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as plugins from './lik.plugins';
|
||||
import { Objectmap } from './lik.objectmap';
|
||||
import { ObjectMap } from './lik.objectmap';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
@ -11,7 +11,7 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
|
||||
/**
|
||||
* stores interests that are currently fullfilled by the cache
|
||||
*/
|
||||
private interestObjectMap = new Objectmap<Interest<DTInterestId, DTInterestFullfillment>>();
|
||||
private interestObjectMap = new ObjectMap<Interest<DTInterestId, DTInterestFullfillment>>();
|
||||
|
||||
/**
|
||||
* a function to compare interests
|
||||
|
@ -1,9 +1,9 @@
|
||||
import * as plugins from './lik.plugins';
|
||||
|
||||
import { Objectmap } from './lik.objectmap';
|
||||
import { ObjectMap } from './lik.objectmap';
|
||||
|
||||
export class LoopTracker<T> {
|
||||
referenceObjectMap = new Objectmap<any>();
|
||||
referenceObjectMap = new ObjectMap<any>();
|
||||
constructor() {
|
||||
// nothing here
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ export interface IObjectmapFindFunction<T> {
|
||||
/**
|
||||
* allows keeping track of objects
|
||||
*/
|
||||
export class Objectmap<T> {
|
||||
export class ObjectMap<T> {
|
||||
private fastMap = new FastMap<T>();
|
||||
|
||||
// events
|
||||
@ -186,4 +186,23 @@ export class Objectmap<T> {
|
||||
this.fastMap.removeFromMap(keyArg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a new Objectmap that includes
|
||||
*/
|
||||
public concat(objectMapArg: ObjectMap<T>) {
|
||||
const concattedObjectMap = new ObjectMap<T>();
|
||||
concattedObjectMap.fastMap.addAllFromOther(this.fastMap);
|
||||
concattedObjectMap.fastMap.addAllFromOther(objectMapArg.fastMap);
|
||||
return concattedObjectMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* tries to merge another Objectmap
|
||||
* Note: uniqueKeyCollisions will cause overwrite
|
||||
* @param objectMapArg
|
||||
*/
|
||||
public addAllFromOther(objectMapArg: ObjectMap<T>) {
|
||||
this.fastMap.addAllFromOther(objectMapArg.fastMap);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user