* Clone shallow. * * @param clonedDims Determine which dims to clone. Will share the data if not specified.
(clonedDims?: DimensionIndex[], ignoreIndices?: boolean)
| 1226 | * @param clonedDims Determine which dims to clone. Will share the data if not specified. |
| 1227 | */ |
| 1228 | clone(clonedDims?: DimensionIndex[], ignoreIndices?: boolean): DataStore { |
| 1229 | const target = new DataStore(); |
| 1230 | const chunks = this._chunks; |
| 1231 | const clonedDimsMap = clonedDims && reduce(clonedDims, (obj, dimIdx) => { |
| 1232 | obj[dimIdx] = true; |
| 1233 | return obj; |
| 1234 | }, {} as Record<DimensionIndex, boolean>); |
| 1235 | |
| 1236 | if (clonedDimsMap) { |
| 1237 | for (let i = 0; i < chunks.length; i++) { |
| 1238 | // Not clone if dim is not picked. |
| 1239 | target._chunks[i] = !clonedDimsMap[i] ? chunks[i] : cloneChunk(chunks[i]); |
| 1240 | } |
| 1241 | } |
| 1242 | else { |
| 1243 | target._chunks = chunks; |
| 1244 | } |
| 1245 | this._copyCommonProps(target); |
| 1246 | |
| 1247 | if (!ignoreIndices) { |
| 1248 | target._indices = this._cloneIndices(); |
| 1249 | } |
| 1250 | target._updateGetRawIdx(); |
| 1251 | return target; |
| 1252 | } |
| 1253 | |
| 1254 | private _copyCommonProps(target: DataStore): void { |
| 1255 | target._count = this._count; |
no test coverage detected