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

visgl / loaders.gl / 25798210458

13 May 2026 12:10PM UTC coverage: 60.27%. Remained the same
25798210458

push

github

web-flow
Remove caution about LAS v1.4 file support (#3272)

13159 of 24150 branches covered (54.49%)

Branch coverage included in aggregate %.

27149 of 42729 relevant lines covered (63.54%)

15182.84 hits per line

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

37.29
/modules/tiles/src/utils/managed-array.ts
1
// This file is derived from the Cesium code base under Apache 2 license
2
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
3

4
import {assert} from '@loaders.gl/loader-utils';
5

6
/**
7
 * A wrapper around arrays so that the internal length of the array can be manually managed.
8
 *
9
 * @alias ManagedArray
10
 * @constructor
11
 * @private
12
 *
13
 * @param {Number} [length=0] The initial length of the array.
14
 */
15
export class ManagedArray {
16
  _map = new Map();
880✔
17
  _array: any[];
18
  _length: number;
19

20
  constructor(length = 0) {
880✔
21
    this._array = new Array(length);
880✔
22
    this._length = length;
880✔
23
  }
24

25
  /**
26
   * Gets or sets the length of the array.
27
   * If the set length is greater than the length of the internal array, the internal array is resized.
28
   *
29
   * @memberof ManagedArray.prototype
30
   * @type Number
31
   */
32
  get length() {
33
    return this._length;
408✔
34
  }
35

36
  set length(length) {
37
    this._length = length;
248✔
38
    if (length > this._array.length) {
248✔
39
      this._array.length = length;
102✔
40
    }
41
  }
42

43
  /**
44
   * Gets the internal array.
45
   *
46
   * @memberof ManagedArray.prototype
47
   * @type Array
48
   * @readonly
49
   */
50
  get values() {
51
    return this._array;
×
52
  }
53

54
  /**
55
   * Gets the element at an index.
56
   *
57
   * @param {Number} index The index to get.
58
   */
59
  get(index) {
60
    assert(index < this._array.length);
×
61
    return this._array[index];
×
62
  }
63

64
  /**
65
   * Sets the element at an index. Resizes the array if index is greater than the length of the array.
66
   *
67
   * @param {Number} index The index to set.
68
   * @param {*} element The element to set at index.
69
   */
70
  set(index, element) {
71
    assert(index >= 0);
×
72

73
    if (index >= this.length) {
×
74
      this.length = index + 1;
×
75
    }
76

77
    if (this._map.has(this._array[index])) {
×
78
      this._map.delete(this._array[index]);
×
79
    }
80

81
    this._array[index] = element;
×
82
    this._map.set(element, index);
×
83
  }
84

85
  delete(element) {
86
    const index = this._map.get(element);
×
87
    if (index >= 0) {
×
88
      this._array.splice(index, 1);
×
89
      this._map.delete(element);
×
90
      this.length--;
×
91
    }
92
  }
93

94
  /**
95
   * Returns the last element in the array without modifying the array.
96
   *
97
   * @returns {*} The last element in the array.
98
   */
99
  peek() {
100
    return this._array[this._length - 1];
×
101
  }
102

103
  /**
104
   * Push an element into the array.
105
   *
106
   * @param {*} element The element to push.
107
   */
108
  push(element) {
109
    if (!this._map.has(element)) {
124!
110
      const index = this.length++;
124✔
111
      this._array[index] = element;
124✔
112
      this._map.set(element, index);
124✔
113
    }
114
  }
115

116
  /**
117
   * Pop an element from the array.
118
   *
119
   * @returns {*} The last element in the array.
120
   */
121
  pop() {
122
    const element = this._array[--this.length];
124✔
123
    this._map.delete(element);
124✔
124
    return element;
124✔
125
  }
126

127
  /**
128
   * Resize the internal array if length > _array.length.
129
   *
130
   * @param {Number} length The length.
131
   */
132
  reserve(length) {
133
    assert(length >= 0);
×
134

135
    if (length > this._array.length) {
×
136
      this._array.length = length;
×
137
    }
138
  }
139

140
  /**
141
   * Resize the array.
142
   *
143
   * @param {Number} length The length.
144
   */
145
  resize(length) {
146
    assert(length >= 0);
×
147

148
    this.length = length;
×
149
  }
150

151
  /**
152
   * Trim the internal array to the specified length. Defaults to the current length.
153
   *
154
   * @param {Number} [length] The length.
155
   */
156
  trim(length) {
157
    if (length === null || length === undefined) {
×
158
      length = this.length;
×
159
    }
160
    this._array.length = length;
×
161
  }
162

163
  reset() {
164
    this._array = [];
72✔
165
    this._map = new Map();
72✔
166
    this._length = 0;
72✔
167
  }
168

169
  find(target) {
170
    return this._map.has(target);
88✔
171
  }
172
}
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