예제 #1
0
        public bool Get(Guid key, out byte[] val)
        {
            val = null;
            var bkey = key.ToByteArray();
            int hc   = (int)Helper.Murmur.Hash(bkey);

            if (_db.Get(hc, out val))
            {
                // unpack data
                byte[] g;
                if (UnpackData(val, out val, out g))
                {
                    if (!Helper.BytewiseEquals(bkey, g))
                    {
                        // if data not equal check duplicates (hash conflict)
                        var ints = new List <int>(_db.GetDuplicates(hc));
                        ints.Reverse();
                        foreach (int i in ints)
                        {
                            var bb = _db.FetchRecordBytes(i);
                            if (UnpackData(bb, out val, out g))
                            {
                                if (Helper.BytewiseEquals(bkey, g))
                                {
                                    return(true);
                                }
                            }
                        }
                        return(false);
                    }
                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
        public bool Get(string key, out byte[] val)
        {
            string str = (_caseSensitive ? key : key.ToLower());

            val = null;
            var bkey = Encoding.Unicode.GetBytes(str);
            int hc   = (int)Helper.Murmur.Hash(bkey);

            if (_db.Get(hc, out val))
            {
                // unpack data
                byte[] g;
                if (UnpackData(val, out val, out g))
                {
                    if (!Helper.BytewiseEquals(bkey, g))
                    {
                        // if data not equal check duplicates (hash conflict)
                        var ints = new List <int>(_db.GetDuplicates(hc));
                        ints.Reverse();
                        foreach (int i in ints)
                        {
                            var bb = _db.FetchRecordBytes(i);
                            if (UnpackData(bb, out val, out g))
                            {
                                if (Helper.BytewiseEquals(bkey, g))
                                {
                                    return(true);
                                }
                            }
                        }
                        return(false);
                    }
                    return(true);
                }
            }
            return(false);
        }