* Data iteration * @param ctx default this * @example * list.each(0, function (x, idx) {}); * list.each([0, 1], function (x, y, idx) {}); * list.each(function (idx) {})
(dims: DimensionIndex[], cb: EachCb)
| 1098 | * list.each(function (idx) {}) |
| 1099 | */ |
| 1100 | each(dims: DimensionIndex[], cb: EachCb): void { |
| 1101 | if (!this._count) { |
| 1102 | return; |
| 1103 | } |
| 1104 | const dimSize = dims.length; |
| 1105 | const chunks = this._chunks; |
| 1106 | |
| 1107 | for (let i = 0, len = this.count(); i < len; i++) { |
| 1108 | const rawIdx = this.getRawIndex(i); |
| 1109 | // Simple optimization |
| 1110 | switch (dimSize) { |
| 1111 | case 0: |
| 1112 | (cb as EachCb0)(i); |
| 1113 | break; |
| 1114 | case 1: |
| 1115 | (cb as EachCb1)(chunks[dims[0]][rawIdx], i); |
| 1116 | break; |
| 1117 | case 2: |
| 1118 | (cb as EachCb2)( |
| 1119 | chunks[dims[0]][rawIdx], chunks[dims[1]][rawIdx], i |
| 1120 | ); |
| 1121 | break; |
| 1122 | default: |
| 1123 | let k = 0; |
| 1124 | const value = []; |
| 1125 | for (; k < dimSize; k++) { |
| 1126 | value[k] = chunks[dims[k]][rawIdx]; |
| 1127 | } |
| 1128 | // Index |
| 1129 | value[k] = i; |
| 1130 | (cb as EachCb).apply(null, value); |
| 1131 | } |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | getDataExtent( |
| 1136 | dim: DimensionIndex, |
no test coverage detected