Beispiel #1
0
        public int InsertOne(string newString)
        {
            bool hasNew;

            byte[] encode = staticFreqEncoding.Encode(newString, out hasNew);

            var checkSum = new Bytes2Longs(encode);

            int code;

            if (hasNew || !coding.TryGetValue(checkSum, out code) || code == Int32.MinValue)
            {
                coding.Add(checkSum, code = coding.Count);
            }
            return(code);
        }
Beispiel #2
0
        private bool Equals(Bytes2Longs other)
        {
            bool rest = Int == other.Int && Short == other.Short && Byte == other.Byte;

            if (!rest)
            {
                return(false);
            }
            if (Longs == null && other.Longs == null)
            {
                return(true);
            }
            if (Longs.Length != other.Longs.Length)
            {
                return(false);
            }

            ulong[] longs = Longs;
            return(Enumerable.Range(0, longs.Length).All(i => longs[i] == other.Longs[i]));
        }
Beispiel #3
0
        public int GetCode(string name)
        {
            Open(true);
            if (Count == 0)
            {
                return(Int32.MinValue);
            }
            bool hasNew;
            var  longs = new Bytes2Longs(staticFreqEncoding.Encode(name, out hasNew));

            if (hasNew)
            {
                return(int.MinValue);
            }
            int code;

            if (!coding.TryGetValue(longs, out code))
            {
                return(int.MinValue);
            }
            return(code);
        }
Beispiel #4
0
        public StringIntEncoded(string path)
        {
            IStringIntCoding existed;

            if (Opend.TryGetValue(path, out existed))
            {
                existed.Close();
                Opend.Remove(path);
            }
            encodedCellPath = path + "encoded.pac";
            pathCiCell      = path + "c_index.pac";

            // Создание ячеек, предполагается, что все либо есть либо их нет и надо создавать
            if (!File.Exists(encodedCellPath) || !File.Exists(pathCiCell))
            {
                Clear();
            }

            // Открытие ячеек в режиме работы (чтения)
            Open(true);
            Count = Convert.ToInt32(c_index.Root.Count());
            Opend.Add(path, this);

            staticFreqEncoding = new StaticFreqEncoding();
            coding             = new Dictionary <Bytes2Longs, int>();
            if (Count > 0)
            {
                foreach (object[] q in encodedCell.Root.ElementValues())
                {
                    byte[]      bytes       = q.Cast <byte>().ToArray();
                    Bytes2Longs bytes2Longs = new Bytes2Longs(bytes);

                    coding.Add(bytes2Longs, coding.Count);
                }
            }
        }