public BasicSet(DATA_TYPE keyType, ExtendedDataInput @in) { this.keyType = keyType; BasicEntityFactory factory = new BasicEntityFactory(); DATA_TYPE[] types = Enum.GetValues(typeof(DATA_TYPE)) as DATA_TYPE[]; //read key vector short flag = @in.readShort(); int form = flag >> 8; int type = flag & 0xff; if (form != (int)DATA_FORM.DF_VECTOR) { throw new IOException("The form of set keys must be vector"); } if (type < 0 || type >= types.Length) { throw new IOException("Invalid key type: " + type); } IVector keys = (IVector)factory.createEntity(DATA_FORM.DF_VECTOR, types[type], @in); int size = keys.rows(); set = new HashSet <IScalar>(); for (int i = 0; i < size; ++i) { set.Add(keys.get(i)); } }
protected internal BasicAnyVector(ExtendedDataInput @in) : base(DATA_FORM.DF_VECTOR) { int rows = @in.readInt(); int cols = @in.readInt(); int size = rows * cols; values = new IEntity[size]; BasicEntityFactory factory = new BasicEntityFactory(); for (int i = 0; i < size; ++i) { short flag = @in.readShort(); int form = flag >> 8; int type = flag & 0xff; bool extended = type >= 128; if (type >= 128) { type -= 128; } //if (form != 1) //assert (form == 1); //if (type != 4) //assert(type == 4); IEntity obj = factory.createEntity((DATA_FORM)form, (DATA_TYPE)type, @in, extended); values[i] = obj; } }
public BasicTable(ExtendedDataInput @in) { int rows = @in.readInt(); int cols = @in.readInt(); _tableName = @in.readString(); //read column names for (int i = 0; i < cols; ++i) { string name = @in.readString(); name2index_[name] = name2index_.Count; names_.Add(name); } BasicEntityFactory factory = new BasicEntityFactory(); //read columns for (int i = 0; i < cols; ++i) { short flag = @in.readShort(); int form = flag >> 8; int type = flag & 0xff; DATA_FORM df = (DATA_FORM)form; DATA_TYPE dt = (DATA_TYPE)type; if (df != DATA_FORM.DF_VECTOR) { throw new IOException("Invalid form for column [" + names_[i] + "] for table " + _tableName); } Console.WriteLine("vector create " + i + ":" + DateTime.Now); IVector vector = (IVector)factory.createEntity(df, dt, @in); Console.WriteLine("vector end create " + i + ":" + DateTime.Now); if (vector.rows() != rows && vector.rows() != 1) { throw new IOException("The number of rows for column " + names_[i] + " is not consistent with other columns"); } columns_.Add(vector); } }
public BasicDictionary(DATA_TYPE valueType, ExtendedDataInput @in) { this.valueType = valueType; BasicEntityFactory factory = new BasicEntityFactory(); DATA_TYPE[] types = Enum.GetValues(typeof(DATA_TYPE)) as DATA_TYPE[]; //read key vector short flag = @in.readShort(); int form = flag >> 8; int type = flag & 0xff; if (form != (int)DATA_FORM.DF_VECTOR) { throw new IOException("The form of dictionary keys must be vector"); } if (type < 0 || type >= types.Length) { throw new IOException("Invalid key type: " + type); } keyType = types[type]; IVector keys = (IVector)factory.createEntity(DATA_FORM.DF_VECTOR, types[type], @in); //read value vector flag = @in.readShort(); form = flag >> 8; type = flag & 0xff; if (form != (int)DATA_FORM.DF_VECTOR) { throw new IOException("The form of dictionary values must be vector"); } if (type < 0 || type >= types.Length) { throw new IOException("Invalid value type: " + type); } IVector values = (IVector)factory.createEntity(DATA_FORM.DF_VECTOR, types[type], @in); if (keys.rows() != values.rows()) { throw new IOException("The key size doesn't equate to value size."); } int size = keys.rows(); int capacity = (int)(size / 0.75); dict = new Dictionary <IScalar, IEntity>(capacity); if (values.getDataType() == DATA_TYPE.DT_ANY) { BasicAnyVector entityValues = (BasicAnyVector)values; for (int i = 0; i < size; ++i) { dict[keys.get(i)] = entityValues.getEntity(i); } } else { for (int i = 0; i < size; ++i) { dict[keys.get(i)] = values.get(i); } } }
public BasicTable(ExtendedDataInput @in) { int rows = @in.readInt(); int cols = @in.readInt(); _tableName = @in.readString(); //read column names for (int i = 0; i < cols; ++i) { string name = @in.readString(); name2index_[name] = name2index_.Count; names_.Add(name); } BasicEntityFactory factory = new BasicEntityFactory(); VectorDecompressor decompressor = null; SymbolBaseCollection collection = null; //read columns for (int i = 0; i < cols; ++i) { short flag = @in.readShort(); int form = flag >> 8; int type = flag & 0xff; bool extended = type >= 128; if (type >= 128) { type -= 128; } DATA_FORM df = (DATA_FORM)form; DATA_TYPE dt = (DATA_TYPE)type; if (df != DATA_FORM.DF_VECTOR) { throw new IOException("Invalid form for column [" + names_[i] + "] for table " + _tableName); } IVector vector; if (dt == DATA_TYPE.DT_SYMBOL && extended) { if (collection == null) { collection = new SymbolBaseCollection(); } vector = new BasicSymbolVector(df, @in, collection); } else if (dt == DATA_TYPE.DT_COMPRESS) { if (decompressor == null) { decompressor = new VectorDecompressor(); } vector = decompressor.Decompress(factory, @in, false, true); } else { vector = (IVector)factory.createEntity(df, dt, @in, extended); } if (vector.rows() != rows && vector.rows() != 1) { int tmp = vector.rows(); throw new IOException("The number of rows for column " + names_[i] + " is not consistent with other columns"); } columns_.Add(vector); } }