Esempio n. 1
0
 // If memtable contains a value for key, store it in *value and return true.
 // If memtable contains a deletion for key, store a NotFound() error
 // in *status and return true.
 // Else, return false.
 public bool Get(LookupKey key, ref string value, ref Status s)
 {
     Slice memkey = key.GetMemTableKey();
     SkipList.Iterator iter = new SkipList.Iterator(m_table);
     iter.Seek(memkey.Data);
     if (iter.Valid)
     {
         // entry format is:
         //    klength  varint32
         //    userkey  char[klength]
         //    tag      uint64
         //    vlength  varint32
         //    value    char[vlength]
         // Check that it belongs to same user key.  We do not check the
         // sequence number since the Seek() call above should have skipped
         // all entries with overly large sequence numbers.
         ByteArrayPointer entry = iter.Key;
         UInt32 key_length;
         ByteArrayPointer key_ptr = Coding.GetVarint32Ptr(entry, entry + 5, out key_length);
         if (m_comparator.Comparator.UserComparator.Compare(
                         new Slice(key_ptr, (int)key_length - 8),
                         key.GetUserKey()) == 0)
         {
             // Correct user key
             UInt64 tag = Coding.DecodeFixed64(key_ptr + ((int)key_length - 8));
             switch ((ValueTypeEnum)(tag & 0xff))
             {
                 case ValueTypeEnum.kTypeValue:
                     {
                         Slice v = GetLengthPrefixedSlice(key_ptr + (int)key_length);
                         value = v.Data.GetString(v.Size);
                         return true;
                     }
                 case ValueTypeEnum.kTypeDeletion:
                     s = Status.NotFound(new Slice());
                     return true;
             }
         }
     }
     return false;
 }
Esempio n. 2
0
 public MemTableIterator(SkipList table)
 {
     m_iterator = new SkipList.Iterator(table);
 }