Exemple #1
0
 public BasicSet(DATA_TYPE keyType, int capacity)
 {
     if (keyType == DATA_TYPE.DT_VOID || keyType == DATA_TYPE.DT_SYMBOL || keyType.ordinal() >= (int)DATA_TYPE.DT_FUNCTIONDEF)
     {
         throw new System.ArgumentException("Invalid keyType: " + keyType.name());
     }
     this.keyType = keyType;
     set          = new HashSet <Scalar>();
 }
 public BasicDictionary(DATA_TYPE keyType, DATA_TYPE valueType, int capacity)
 {
     if (keyType == DATA_TYPE.DT_VOID || keyType == DATA_TYPE.DT_ANY || keyType == DATA_TYPE.DT_DICTIONARY)
     {
         throw new System.ArgumentException("Invalid keyType: " + keyType.name());
     }
     this.keyType   = keyType;
     this.valueType = valueType;
     dict           = new Dictionary <Scalar, Entity>();
 }
        public virtual void write(ExtendedDataOutput @out)
        {
            if (valueType == DATA_TYPE.DT_DICTIONARY)
            {
                throw new IOException("Can't streamlize the dictionary with value type " + valueType.name());
            }

            BasicEntityFactory factory = new BasicEntityFactory();
            Vector             keys    = (Vector)factory.createVectorWithDefaultValue(keyType, dict.Count);
            Vector             values  = (Vector)factory.createVectorWithDefaultValue(valueType, dict.Count);
            int index = 0;

            try
            {
                foreach (KeyValuePair <Scalar, Entity> entry in dict.SetOfKeyValuePairs())
                {
                    keys.set(index, entry.Key);
                    values.set(index, (Scalar)entry.Value);
                    ++index;
                }
            }
            catch (Exception ex)
            {
                throw new IOException(ex.Message);
            }

            int flag = ((int)DATA_FORM.DF_DICTIONARY << 8) + DataType.ordinal();

            @out.writeShort(flag);

            keys.write(@out);
            values.write(@out);
        }