All files FastSearch.ts

100% Statements 13/13
100% Branches 8/8
100% Functions 3/3
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28    11x 13x     18x 5362x 249x   5362x 5361x   5362x         1398x 3x   1395x 5x   1390x      
import {DPoint} from './DPoint';
 
export class FastSearch {
  private searchStore: Record<number, Record<number, Record<number | string, boolean>>> = {};
 
  add(points: DPoint[]): void {
    for (const {x, y, z} of points) {
      if (!this.searchStore[x]) {
        this.searchStore[x] = {};
      }
      if (!this.searchStore[x][y]) {
        this.searchStore[x][y] = {};
      }
      this.searchStore[x][y][z || 'undefined'] = true;
    }
  }
 
  find({x, y, z}: DPoint): boolean {
    if (!this.searchStore[x]) {
      return false;
    }
    if (!this.searchStore[x][y]) {
      return false;
    }
    return this.searchStore[x][y][z || 'undefined'];
  }
}