示例#1
0
        public IEnumerable <object[]> GetAllByKey(int column, object key)
        {
            int i;

            for (i = 0; i < cnoms.Length; i++)
            {
                if (cnoms[i] == column)
                {
                    break;
                }
            }
            if (i == cnoms.Length)
            {
                throw new Exception("Err: 938948");
            }

            var index = allindexes[i];

            if (index is IndexDynamic <int, IndexKeyImmutable <int> > )
            {
                IndexDynamic <int, IndexKeyImmutable <int> > ind = (IndexDynamic <int, IndexKeyImmutable <int> >)index;
                return(ind.GetAllByKey((int)key).Select(ent => ((object[])ent.Get())[1]).Cast <object[]>());
            }
            else if (index is IndexDynamic <string, IndexHalfkeyImmutable <string> > )
            {
                IndexDynamic <string, IndexHalfkeyImmutable <string> > ind = (IndexDynamic <string, IndexHalfkeyImmutable <string> >)index;
                return(ind.GetAllByKey((string)key).Select(ent => ((object[])ent.Get())[1]).Cast <object[]>());
            }
            return(Enumerable.Empty <object[]>());
        }
示例#2
0
        public NameTableUniversal(string path)
        {
            this.path = path;
            PType tp_tabelement = new PTypeRecord(
                new NamedType("code", new PType(PTypeEnumeration.integer)),
                new NamedType("str", new PType(PTypeEnumeration.sstring)));

            this.table = new TableView(path + "cstable", tp_tabelement);
            //next_code = (int)table.Count();
            offset_array = new IndexViewImmutable <int>(path + "offsets")
            {
                Table       = this.table,
                KeyProducer = pair => (int)((object[])(((object[])pair)[1]))[0],
                Tosort      = false
            };
            offsets = new IndexDynamic <int, IndexViewImmutable <int> >(true)
            {
                Table = this.table,
                //KeyProducer = pair => (int)((object[])pair)[0],
                KeyProducer = pair => (int)((object[])(((object[])pair)[1]))[0],
                IndexArray  = offset_array
            };
            table.RegisterIndex(offsets);
            s_index_array_path = path + "s_index";

            s_index_array = new IndexHalfkeyImmutable <string>(s_index_array_path)
            {
                Table        = table,
                KeyProducer  = pair => (string)((object[])(((object[])pair)[1]))[1],
                HalfProducer = key => key.GetHashCode()
            };
            s_index_array.Scale = new ScaleCell(path + "dyna_index_str_half")
            {
                IndexCell = s_index_array.IndexCell
            };
            //s_index_array.Scale = new ScaleMemory() { IndexCell = s_index_array.IndexCell };
            s_index = new IndexDynamic <string, IndexHalfkeyImmutable <string> >(true)
            {
                Table       = table,
                KeyProducer = pair => (string)((object[])(((object[])pair)[1]))[1],
                IndexArray  = s_index_array
            };
            table.RegisterIndex(s_index);
        }
示例#3
0
        public TableSimple(PType tp_elem, int[] indexcolumnnoms, Func <Stream> getstream)
        {
            this.tp_element = tp_elem;
            this.getstream  = getstream;
            this.cnoms      = indexcolumnnoms;
            table           = new TableView(getstream(), tp_elem);
            if (tp_element.Vid != PTypeEnumeration.record)
            {
                throw new Exception("Err in TableRelational Indexes: Type of element is not record");
            }
            allindexes = new IIndexCommon[cnoms.Length];
            PTypeRecord tp_r = (PTypeRecord)tp_element;
            int         i    = 0;

            foreach (int nom in cnoms)
            {
                if (nom < 0 || nom > tp_r.Fields.Length)
                {
                    throw new Exception("Err in TableRelational Indexes: element number is out of range");
                }
                PType tp = tp_r.Fields[nom].Type;
                if (tp.Vid == PTypeEnumeration.integer)
                {
                    Func <object, int>      keyproducer = v => (int)((object[])((object[])v)[1])[nom];
                    IndexKeyImmutable <int> ind_arr     = new IndexKeyImmutable <int>(getstream())
                    {
                        Table       = table,
                        KeyProducer = keyproducer,
                        Scale       = null
                    };
                    ind_arr.Scale = new ScaleCell(getstream())
                    {
                        IndexCell = ind_arr.IndexCell
                    };
                    IndexDynamic <int, IndexKeyImmutable <int> > index = new IndexDynamic <int, IndexKeyImmutable <int> >(true, ind_arr);
                    allindexes[i] = index;
                    table.RegisterIndex(index);
                }
                else if (tp.Vid == PTypeEnumeration.sstring)
                {
                    IndexHalfkeyImmutable <string> index_arr = new IndexHalfkeyImmutable <string>(getstream())
                    {
                        Table        = table,
                        KeyProducer  = v => (string)((object[])((object[])v)[1])[nom],
                        HalfProducer = v => Hashfunctions.HashRot13(v)
                    };
                    index_arr.Scale = new ScaleCell(getstream())
                    {
                        IndexCell = index_arr.IndexCell
                    };
                    IndexDynamic <string, IndexHalfkeyImmutable <string> > index =
                        new IndexDynamic <string, IndexHalfkeyImmutable <string> >(false, index_arr);
                    allindexes[i] = index;
                    table.RegisterIndex(index);
                }
                else
                {
                    throw new Exception($"Err: vid {tp.Vid} is not implemented in TableRelational Indexes");
                }
                i++;
            }
        }