• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Open-S2 / gis-tools / #6

23 Jan 2025 11:00PM UTC coverage: 92.693% (-0.3%) from 93.021%
#6

push

Mr Martian
gridCluster done; toTiles setup without tests; dataStores add has; fixed geometry 3dpoint to normalize from wm and s2 data

120 of 399 new or added lines in 24 files covered. (30.08%)

26 existing lines in 9 files now uncovered.

59825 of 64541 relevant lines covered (92.69%)

95.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/src/dataStore/vector/index.ts
1
import { compareIDs } from '../..';
110✔
2

3
import type { S2CellId } from '../..';
4

5
/** The kind of input required to store a vector for proper indexing */
6
export interface VectorKey {
7
  cell: S2CellId;
8
}
9

10
/** Represents a vector store or an array */
11
export interface VectorStore<V> {
12
  push: (value: V) => void;
13
  get: (index: number | S2CellId) => Promise<V>;
14
  has: (key: number | S2CellId) => boolean | Promise<boolean>;
15
  length: number;
16
  values: () => AsyncGenerator<V>;
17
  sort: (() => void) | (() => Promise<void>);
18
  [Symbol.asyncIterator]: () => AsyncGenerator<V>;
19
  close: () => void;
20
}
21

22
/** A constructor for a vector store */
23
export type VectorStoreConstructor<V extends VectorKey> = new () => VectorStore<V>;
24

25
/** A local vector key-value store */
26
export class Vector<V extends VectorKey> implements VectorStore<V> {
88✔
27
  #store: V[] = [];
54✔
28

29
  /**
30
   * Push a value into the store
31
   * @param value - the value to store
32
   */
33
  push(value: V): void {
48✔
34
    this.#store.push(value);
134✔
35
  }
36

37
  /**
38
   * @param index - the position in the store to get the value from
39
   * @returns the value
40
   */
41
  async get(index: number | S2CellId): Promise<V> {
46✔
42
    return await this.#store[Number(index)];
184✔
43
  }
44

45
  /**
46
   * Check if the key exists
47
   * @param key - the key
48
   * @returns true if the key exists
49
   */
NEW
50
  has(key: number | S2CellId): boolean {
×
51
    return this.#store[Number(key)] !== undefined;
118✔
52
  }
53

54
  /** @returns the length of the store */
55
  get length(): number {
32✔
56
    return this.#store.length;
140✔
57
  }
58

59
  /**
60
   * iterate through the values
61
   * @yields an iterator
62
   */
63
  async *values(): AsyncGenerator<V> {
30✔
64
    for (const value of this.#store) yield value;
226✔
65
  }
66

67
  /** Sort the store in place */
68
  sort(): void {
28✔
69
    this.#store.sort((a, b): -1 | 0 | 1 => {
126✔
70
      return compareIDs(a.cell, b.cell);
164✔
71
    });
26✔
72
  }
73

74
  /**
75
   * iterate through the values
76
   * @returns an iterator
77
   */
78
  [Symbol.asyncIterator](): AsyncGenerator<V> {
62✔
79
    return this.values();
106✔
80
  }
81

82
  /** Closes the store */
83
  close(): void {
30✔
84
    this.#store = [];
94✔
85
  }
86
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc