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QACtB,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC;IACpD,CAAC;CACJ;AApED,8CAoEC","file":"dictionary.js","sourcesContent":["// Licensed to the Apache Software Foundation (ASF) under one\n// or more contributor license agreements. See the NOTICE file\n// distributed with this work for additional information\n// regarding copyright ownership. The ASF licenses this file\n// to you under the Apache License, Version 2.0 (the\n// \"License\"); you may not use this file except in compliance\n// with the License. You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing,\n// software distributed under the License is distributed on an\n// \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n// KIND, either express or implied. See the License for the\n// specific language governing permissions and limitations\n// under the License.\n\nimport { Vector } from '../vector';\nimport { IntBuilder } from './int';\nimport { Dictionary, DataType } from '../type';\nimport { Builder, BuilderOptions } from '../builder';\n\ntype DictionaryHashFunction = (x: any) => string | number;\n\nexport interface DictionaryBuilderOptions extends BuilderOptions {\n dictionaryHashFunction?: DictionaryHashFunction;\n}\n\n/** @ignore */\nexport class DictionaryBuilder extends Builder {\n\n protected _dictionaryOffset: number;\n protected _dictionary?: Vector;\n protected _keysToIndices: { [key: string]: number };\n public readonly indices: IntBuilder;\n public readonly dictionary: Builder;\n\n constructor({ 'type': type, 'nullValues': nulls, 'dictionaryHashFunction': hashFn }: DictionaryBuilderOptions) {\n super({ type: new Dictionary(type.dictionary, type.indices, type.id, type.isOrdered) as T });\n this._nulls = null;\n this._dictionaryOffset = 0;\n this._keysToIndices = Object.create(null);\n this.indices = Builder.new({ 'type': this.type.indices, 'nullValues': nulls }) as IntBuilder;\n this.dictionary = Builder.new({ 'type': this.type.dictionary, 'nullValues': null }) as Builder;\n if (typeof hashFn === 'function') {\n this.valueToKey = hashFn;\n }\n }\n\n public get values() { return this.indices.values; }\n public get nullCount() { return this.indices.nullCount; }\n public get nullBitmap() { return this.indices.nullBitmap; }\n public get byteLength() { return this.indices.byteLength + this.dictionary.byteLength; }\n public get reservedLength() { return this.indices.reservedLength + this.dictionary.reservedLength; }\n public get reservedByteLength() { return this.indices.reservedByteLength + this.dictionary.reservedByteLength; }\n public isValid(value: T['TValue'] | TNull) { return this.indices.isValid(value); }\n public setValid(index: number, valid: boolean) {\n const indices = this.indices;\n valid = indices.setValid(index, valid);\n this.length = indices.length;\n return valid;\n }\n public setValue(index: number, value: T['TValue']) {\n let keysToIndices = this._keysToIndices;\n let key = this.valueToKey(value);\n let idx = keysToIndices[key];\n if (idx === undefined) {\n keysToIndices[key] = idx = this._dictionaryOffset + this.dictionary.append(value).length - 1;\n }\n return this.indices.setValue(index, idx);\n }\n public flush() {\n const type = this.type;\n const prev = this._dictionary;\n const curr = this.dictionary.toVector();\n const data = this.indices.flush().clone(type);\n data.dictionary = prev ? prev.concat(curr) : curr;\n this.finished || (this._dictionaryOffset += curr.length);\n this._dictionary = data.dictionary as Vector;\n this.clear();\n return data;\n }\n public finish() {\n this.indices.finish();\n this.dictionary.finish();\n this._dictionaryOffset = 0;\n this._keysToIndices = Object.create(null);\n return super.finish();\n }\n public clear() {\n this.indices.clear();\n this.dictionary.clear();\n return super.clear();\n }\n public valueToKey(val: any): string | number {\n return typeof val === 'string' ? val : `${val}`;\n }\n}\n"]}