public BasicArrayVector(DATA_TYPE type) : base(DATA_FORM.DF_VECTOR) { this.type = type; this.rowIndices = new List <int>(); DATA_TYPE valueType = type - 64; valueVec = (AbstractVector)BasicEntityFactory.instance().createVectorWithDefaultValue(valueType, 0); this.baseUnitLength_ = valueVec.getUnitLength(); }
public BasicArrayVector(List <IVector> value) : base(DATA_FORM.DF_VECTOR) { DATA_TYPE valueType = value[0].getDataType(); this.type = valueType + 64; int count = 0; int indexCount = value.Count; foreach (IVector temp in value) { if (temp.rows() == 0) { count += 1; } else { count += temp.rows(); } } int indexPos = 0; this.rowIndices = new List <int>(new int[indexCount]); this.valueVec = (AbstractVector)BasicEntityFactory.instance().createVectorWithDefaultValue(valueType, count); int index = 0; int curRows = 0; for (int valuePos = 0; valuePos < indexCount; ++valuePos) { IVector temp = value[valuePos]; int size = temp.rows(); for (int i = 0; i < size; ++i) { this.valueVec.set(index, temp.get(i)); index++; } if (size == 0) { size = 1; this.valueVec.setNull(index); index++; } curRows += size; this.rowIndices[indexPos++] = curRows; } this.baseUnitLength_ = (this.valueVec).getUnitLength(); }
public override void append(IVector value) { if (value is IVector) { int indexCount = rowIndices.Count; int prev = indexCount == 0 ? 0 : rowIndices[indexCount - 1]; if (((IVector)value).rows() != 0) { rowIndices.Add(prev + value.rows()); valueVec.append(value); } else { rowIndices.Add(prev + 1); IScalar scalar = BasicEntityFactory.instance().createScalarWithDefaultValue(value.getDataType()); scalar.setNull(); valueVec.append(scalar); } } else { throw new Exception("Append to arrayctor must be a vector. "); } }
public BasicArrayVector(DATA_TYPE type, ExtendedDataInput @in) : base(DATA_FORM.DF_VECTOR) { this.type = type; int rows = @in.readInt(); int cols = @in.readInt(); rowIndices = new List <int>(new int[rows]); DATA_TYPE valueType = type - 64; valueVec = (AbstractVector)BasicEntityFactory.instance().createVectorWithDefaultValue(valueType, cols); this.baseUnitLength_ = valueVec.getUnitLength(); int rowsRead = 0; int rowsReadInBlock = 0; int prevIndex = 0; int totalBytes = 0; while (rowsRead < rows) { //read block header int blockRows = @in.readShort(); int countBytes = @in.readChar(); @in.skipBytes(1); //read array of count totalBytes = blockRows * countBytes; rowsReadInBlock = 0; int offect = 0; while (offect < totalBytes) { int len = Math.Min(BUF_SIZE, totalBytes - offect); @in.readFully(buf, 0, len); int curRows = len / countBytes; if (countBytes == 1) { for (int i = 0; i < curRows; i++) { int curRowCells = buf[i]; rowIndices[rowsRead + rowsReadInBlock + i] = prevIndex + curRowCells; prevIndex += curRowCells; } } else if (countBytes == 2) { for (int i = 0; i < curRows; ++i) { int curRowCells = BitConverter.ToInt16(buf, i * 2); rowIndices[rowsRead + rowsReadInBlock + i] = prevIndex + curRowCells; prevIndex += curRowCells; } } else { for (int i = 0; i < curRows; ++i) { int curRowCells = BitConverter.ToInt32(buf, i * 4); rowIndices[rowsRead + rowsReadInBlock + i] = prevIndex + curRowCells; prevIndex += curRowCells; } } rowsReadInBlock += curRows; offect += len; } //read array of values int rowStart = rowsRead == 0 ? 0 : rowIndices[rowsRead - 1]; int valueCount = rowIndices[rowsRead + rowsReadInBlock - 1] - rowStart; valueVec.deserialize(rowStart, valueCount, @in); rowsRead += rowsReadInBlock; } }