Gets the table entry for the given segment and hash
517158
@SuppressWarnings("unchecked")
    static final <K,V> HashEntry<K,V> entryForHash(Segment<K,V> seg, int h) {
        HashEntry<K,V>[] tab;
        return (seg == null || (tab = seg.table) == null) ? null :
            (HashEntry<K,V>) UNSAFE.getObjectVolatile
            (tab, ((long)(((tab.length - 1) & h)) << TSHIFT) + TBASE);
    }
129787
def getTable(self, layer, where="1 = 1", fields=[], jsobj=None):
        
        base_where = where
        features = []
        # We always want to run once, and then break out as soon as we stop
        # getting exceededTransferLimit.
        while True:
            features += [feat.get('attributes') for feat in jsobj.get('features')]
            # There isn't an exceededTransferLimit?
            if len(jsobj.get('features')) < 1000:
                break
            # If we've hit the transfer limit we offset by the last OBJECTID
            # returned and keep moving along.
            where = "%s > %s" % (self.object_id_field, features[-1].get(self.object_id_field))
            if base_where != "1 = 1" :
                # If we have another WHERE filter we needed to tack that back on.
                where += " AND %s" % base_where
            jsobj = self.get_json(layer, where, fields)
        return features
423158
def get(path, headers: {}, query: {})
      @parent.get("/#{@segment}/#{path}".gsub(%r{/+}, '/'),
                  headers: @default_headers.merge(headers), query: query)
    end
681837
def to_hash
      result = {}
      @lines.entries.each do |section|
        result[section.key] ||= {}
        section.entries.each do |option|
          opts = Array(option)
          val = opts.map { |o| o.respond_to?(:value) ? o.value : o }
          val = val.size > 1 ? val : val.first
          result[section.key][opts.first.key] = val
        end
      end
      result
    end
1255860
def get_entry_for(entry, language)
      if entry.length > 1
        entry_string = get_entry_for_rec(entry[1..-1], language, hashes[language][entry[0]])
      else
        entry_string = hashes[language][entry[0]]
      end

      if entry_string.kind_of?(Array)
        entry_string = entry_string.map(&:inspect).join(', ')
      end
      entry_string
    end
879264
private HashtableEntry findEntry(Object key, int retrieveMode, boolean checkExpired)
                    throws IOException,
                    EOFException,
                    FileManagerException,
                    ClassNotFoundException,
                    HashtableOnDiskException {
        if (key == null) {
            return null;
        }

        int hashcode = key.hashCode();
        int index = header.getHtIndex(hashcode, header.currentTableId());
        long current = 0;
        HashtableEntry answer = null;

        if (header.rehashInProgress == 1) {

            if (debug)
                print("*");

            //
            // First search primary table.
            //
            if (htindex[index] != 0) {
                if (debug)
                    print("A");
                current = htindex[index];

                if (current == 0) {
                    throw new IllegalStateException("findEntry: ht pointer is null");
                }
                answer = findEntry(key, hashcode, retrieveMode, checkExpired, current, header.currentTableId());
                if (answer != null) {
                    return answer;
                }
            }

            //
            // Fell through, now search new table
            //
            index = header.getHtIndex(hashcode, header.alternateTableId());
            if (new_htindex[index] != 0) {
                if (debug)
                    print("B ");
                current = new_htindex[index];
                if (current == 0) {
                    throw new IllegalStateException("findEntry: ht pointer is null");
                }
                return findEntry(key, hashcode, retrieveMode, checkExpired, current, header.alternateTableId());
            }
            //
            // Fell through again, nothing here.
            //
            return null;
        } else {
            if (htindex[index] == 0) {
                return null;
            }
            int tableid = header.currentTableId();
            //current = header.calcOffset(index, tableid);
            current = htindex[index];
            if (current == 0) {
                throw new IllegalStateException("findEntry: ht pointer is null");
            }
            return findEntry(key, hashcode, retrieveMode, checkExpired, current, tableid);
        }
    }
584779
public void readEntries(TableKelp table, 
                          InSegment reader,
                          SegmentEntryCallback cb)
  {
    TempBuffer tBuf = TempBuffer.createLarge();
    byte []buffer = tBuf.buffer();
    
    InStore sIn = reader.getStoreRead();
    byte []tableKey = new byte[TableKelp.TABLE_KEY_SIZE];
    
    for (int ptr = length() - BLOCK_SIZE; ptr > 0; ptr -= BLOCK_SIZE) {
      sIn.read(getAddress() + ptr, buffer, 0, buffer.length);
      
      int index = 0;
      
      long seq = BitsUtil.readLong(buffer, index);
      index += 8;
      
      if (seq != getSequence()) {
        log.warning(L.l("Invalid sequence {0} expected {1} at 0x{2}",
                        seq, 
                        getSequence(),
                        Long.toHexString(getAddress() + ptr)));
        
        break;
      }
      
      System.arraycopy(buffer, index, tableKey, 0, tableKey.length);
      index += tableKey.length;
      
      if (! Arrays.equals(tableKey, _tableKey)) {
        log.warning(L.l("Invalid table {0} table {1} at 0x{2}",
                        Hex.toShortHex(tableKey),
                        Hex.toShortHex(_tableKey),
                        Long.toHexString(getAddress() + ptr)));
        break;
      }
      
      /*
      int tail = BitsUtil.readInt16(buffer, index);
      index += 2;
      
      if (tail <= 0) {
        throw new IllegalStateException();
      }
      */
      
      int head = index;
      while (head < BLOCK_SIZE && buffer[head] != 0) {
        head = readEntry(table, buffer, head, cb, getAddress());
      }
      
      boolean isCont = buffer[head + 1] != 0;
      
      if (! isCont) {
        break;
      }
    }
    
    tBuf.free();
  }
1295049
def getSegmentKeys(self, segment):
        
        return list(filter(lambda x: x.startswith(segment), self.getAliasedKeys()))
924824
def select_sentence(hash)
      thrift_method = "getRowsByScanner"
      thrift_table = hash[:from]
      thrift_columns = hash[:select]
      thrift_filters = recurse_where(hash[:where] || [])
      thrift_limit = hash[:limit]
      
      HipsterSqlToHbase::ThriftCallGroup.new([{:method => thrift_method,:arguments => [thrift_table,thrift_columns,thrift_filters,thrift_limit,{}]}])
    end
1051392
private Optional<String> getTabletLocation(String table, Key key)
    {
        try {
            // Get the Accumulo table ID so we can scan some fun stuff
            String tableId = connector.tableOperations().tableIdMap().get(table);

            // Create our scanner against the metadata table, fetching 'loc' family
            Scanner scanner = connector.createScanner("accumulo.metadata", auths);
            scanner.fetchColumnFamily(new Text("loc"));

            // Set the scan range to just this table, from the table ID to the default tablet
            // row, which is the last listed tablet
            Key defaultTabletRow = new Key(tableId + '<');
            Key start = new Key(tableId);
            Key end = defaultTabletRow.followingKey(PartialKey.ROW);
            scanner.setRange(new Range(start, end));

            Optional<String> location = Optional.empty();
            if (key == null) {
                // if the key is null, then it is -inf, so get first tablet location
                Iterator<Entry<Key, Value>> iter = scanner.iterator();
                if (iter.hasNext()) {
                    location = Optional.of(iter.next().getValue().toString());
                }
            }
            else {
                // Else, we will need to scan through the tablet location data and find the location

                // Create some text objects to do comparison for what we are looking for
                Text splitCompareKey = new Text();
                key.getRow(splitCompareKey);
                Text scannedCompareKey = new Text();

                // Scan the table!
                for (Entry<Key, Value> entry : scanner) {
                    // Get the bytes of the key
                    byte[] keyBytes = entry.getKey().getRow().copyBytes();

                    // If the last byte is <, then we have hit the default tablet, so use this location
                    if (keyBytes[keyBytes.length - 1] == '<') {
                        location = Optional.of(entry.getValue().toString());
                        break;
                    }
                    else {
                        // Chop off some magic nonsense
                        scannedCompareKey.set(keyBytes, 3, keyBytes.length - 3);

                        // Compare the keys, moving along the tablets until the location is found
                        if (scannedCompareKey.getLength() > 0) {
                            int compareTo = splitCompareKey.compareTo(scannedCompareKey);
                            if (compareTo <= 0) {
                                location = Optional.of(entry.getValue().toString());
                            }
                            else {
                                // all future tablets will be greater than this key
                                break;
                            }
                        }
                    }
                }
                scanner.close();
            }

            // If we were unable to find the location for some reason, return the default tablet
            // location
            return location.isPresent() ? location : getDefaultTabletLocation(table);
        }
        catch (Exception e) {
            // Swallow this exception so the query does not fail due to being unable
            // to locate the tablet server for the provided Key.
            // This is purely an optimization, but we will want to log the error.
            LOG.error("Failed to get tablet location, returning dummy location", e);
            return Optional.empty();
        }
    }
407317
private HashtableEntry findEntry(EvictionTableEntry evt, int retrieveMode, long current, int tableid)
                    throws IOException,
                    EOFException,
                    FileManagerException,
                    ClassNotFoundException,
                    HashtableOnDiskException {

        int hashcode = evt.hashcode;
        long previous = 0;

        long next = 0;
        int hash = 0;

        initReadBuffer(current);
        next = headerin.readLong();
        hash = headerin.readInt();

        while (current != 0) {
            //  System.out.println("current:"+current+" next:"+next);
            if (hash == hashcode) { // hash the same?
                // 		
                // Need to finish collision resolution and maybe return the object
                //   System.out.println("hashcode matched, hash:"+ hashcode); 
                HashtableEntry entry = readEntry2(current, next, hash, previous, retrieveMode, !CHECK_EXPIRED, tableid, null, evt); //493877
                if (entry != null) { // 493877 if entry is NOT null, the entry is found.
                    return entry;
                }
            }

            collisions++;
            //
            // Try for next object in bucket
            //
            previous = current;
            current = next;

            if (current != 0) { // optimize - don't read if we know we can't use it
                initReadBuffer(current);
                next = headerin.readLong();
                hash = headerin.readInt();
            }

        }

        //
        // If we fall through we did not find it
        //
        return null;
    }
1191907
def segment_content_handler():
    
    from ligo.lw.lsctables import (SegmentTable, SegmentDefTable,
                                   SegmentSumTable)
    from ligo.lw.ligolw import PartialLIGOLWContentHandler

    def _filter(name, attrs):
        return reduce(
            operator.or_,
            [table_.CheckProperties(name, attrs) for
             table_ in (SegmentTable, SegmentDefTable, SegmentSumTable)])

    return build_content_handler(PartialLIGOLWContentHandler, _filter)
148112
private void readSegmentIndex(ReadStream is, Segment10 segment)
    throws IOException
  {
    int address = segment.length() - BLOCK_SIZE;
    
    TempBuffer tBuf = TempBuffer.create();
    byte []buffer = tBuf.buffer();
    
    is.position(address);
    is.read(buffer, 0, BLOCK_SIZE);
    
    int tail = BitsUtil.readInt16(buffer, FOOTER_OFFSET);
    
    if (tail < TABLE_KEY_SIZE + 8 || tail > BLOCK_SIZE - 8) {
      return;
    }
    
    int offset = INDEX_OFFSET;
    
    while (offset < tail) {
      int type = buffer[offset++] & 0xff;
      
      int pid = BitsUtil.readInt(buffer, offset);
      offset += 4;
      
      int nextPid = BitsUtil.readInt(buffer, offset);
      offset += 4;
      
      int entryAddress = BitsUtil.readInt(buffer, offset);
      offset += 4;
      
      int entryLength = BitsUtil.readInt(buffer, offset);
      offset += 4;
      
      if (pid <= 1) {
        System.out.println("INVALID_PID: " + pid);
        return;
      }
      
      switch (PageType10.values()[type]) {
      case LEAF:
        addLeaf(segment, pid, nextPid, entryAddress, entryLength);
        break;
        
      case LEAF_DELTA:
        addLeafDelta(segment, pid, nextPid, entryAddress, entryLength);
        break;
        
      default:
        System.out.println("UNKNOWN-SEGMENT: " + PageType10.values()[type]);
      }
    }
  }
914067
function HeaderEntry(hash, height) {
  this.hash = hash;
  this.height = height;
  this.prev = null;
  this.next = null;
}
534150
CacheBucketOffset get(long segmentId, UUID keyHash) {
        SegmentKeyCache cache;
        int generation;
        synchronized (this.segmentCaches) {
            generation = this.currentCacheGeneration;
            cache = this.segmentCaches.get(segmentId);
        }

        return cache == null ? null : cache.get(keyHash, generation);
    }
1343061
private void checkEntry(long index, Segment segment, Segment compactSegment) {
    try (Entry entry = segment.get(index)) {
      // If an entry was found, only remove the entry from the segment if it's not a tombstone that has been released.
      if (entry != null) {
        checkEntry(index, entry, segment, compactSegment);
      } else {
        compactSegment.skip(1);
      }
    }
  }
123120
protected HashtableEntry readEntry2(long location,
                                        long next,
                                        int hash,
                                        long previous,
                                        int retrieveMode,
                                        boolean checkExpired,
                                        int tableid,
                                        Object matchKey,
                                        EvictionTableEntry matchEVT)
                    throws IOException,
                    ClassNotFoundException {
        long last_modified = 0;
        long last_referenced = 0;
        long first_created = 0;
        long expiration = -1;
        long validatorExpiration = -1;
        long tempData = -1;
        int dataSize = -1;

        int keySize = -1;
        Object key = null;

        int valueSize = -1;
        int bytes = 0;
        Object value = null;

        int cacheValueSize = 0;
        int cacheValueHashcode = 0; // LI4337-17
        byte[] serializedCacheValue = null;
        boolean isAliasId = false;
        boolean isValidHashcodeForValue = true;

        HashtableEntry htEntry = htoddc.getFromHashtableEntryPool();
        last_modified = headerin.readLong(); // old format: last modified
                                             // new format: VET 
        //
        // NOTE: last_referenced is no longer being maintained! 
        // we use this field for H-word: unused; L-word field for cache value hashcode
        //        
        last_referenced = headerin.readLong(); // old format: last referenced;
                                               // new format: unused (int)
                                               //             hashcode for cache value
        if (last_modified == last_referenced) { // LI4337-17
            isValidHashcodeForValue = false;
            cacheValueHashcode = 0;
            validatorExpiration = -1;
        } else {
            cacheValueHashcode = (int) (last_referenced & HTENTRY_HASHCODE_MASK);
            validatorExpiration = last_modified;
        }

        first_created = headerin.readLong(); // time obj first created
        expiration = headerin.readLong(); // expiration (RET)
        tempData = headerin.readLong(); // old format is grace (-1 means not used;  0 means alias)
                                        // new format: magic number, version, flag & data size
        if (tempData != -1) {
            if (tempData == 0) {
                isAliasId = true;
            } else {
                dataSize = (int) (tempData & HTENTRY_DATA_SIZE_MASK);
                isAliasId = (tempData & HTENTRY_ALIAS_ID) > 0 ? true : false;
                //long hteMagic = tempData & HTENTRY_MAGIC_MASK;
                //if (hteMagic != HTENTRY_MAGIC) {
                //    System.out.println("*** magic not compare received=" + hteMagic + " expected=" + HTENTRY_MAGIC);
                //}
                //long hteVersion = tempData & HTENTRY_VERSION_MASK;
                //if (hteVersion != HTENTRY_VERSION) {
                //    System.out.println("*** magic not compare received=" + hteVersion + " expected=" + HTENTRY_VERSION);
                //}
                //long hteFlags = tempData & HTENTRY_FLAGS_MASK;
                //if (hteFlags != 0) {
                //    System.out.println("*** magic not compare received=" + hteFlags + " expected=0");
                //}
            }
        }

        // if matchEVT is valid, compare the expiration time and size key. If not match, the code returns NULL.
        if (matchEVT != null) { //493877
            long expTime = expiration;
            if (expiration <= 0)
                expTime = Long.MAX_VALUE;
            if (expTime != matchEVT.expirationTime || dataSize != matchEVT.size) {
                return null;
            }
        }

        keySize = headerin.readInt(); // length of serialized key

        if ((keybuf == null) || (keybuf.length < keySize)) { // insure desrializion buffer is ok
            keybuf = new byte[keySize];
        }
        filemgr.read(keybuf, 0, keySize); // read key from disk

        deserializeTimer.reset();

        key = SerializationUtility.deserialize(Arrays.copyOf(keybuf, keySize), htoddc.cacheName); // deserialize the key
        deserialize_time += deserializeTimer.elapsed();
        bytes_deserialized += keySize;

        // if matchKey is valid, compare the key whether it matches or not. If not match, the code returns NULL.
        if (matchKey != null && key != null && !key.equals(matchKey)) { //493877
            return null;
        }

        if (checkExpired && expiration > 0) {
            if (System.currentTimeMillis() - expiration >= 0) {
                retrieveMode = RETRIEVE_KEY;
            }
        }

        if (retrieveMode == RETRIEVE_ALL || retrieveMode == RETRIEVE_KEY_VALUE) { // both key and data requested?
            bytes = filemgr.readInt(); // read byte flag
            valueSize = filemgr.readInt(); // read data length
            if (valueSize != -1) { // has data?
                value = readDataField(bytes, valueSize); // read data if byte flag 1 => don't deserialize on data; if byte flag = 0 => deserialize the data
            }
            if (this.bHasCacheValue && dataSize > 0) {
                cacheValueSize = dataSize - keySize - valueSize;
            }
        }

        if (this.bHasCacheValue && !isAliasId && dataSize > 0 && retrieveMode == RETRIEVE_ALL) {
            cacheValueSize = filemgr.readInt(); //read cacheValue length  
            if (cacheValueSize != -1) { // has cacheValue?
                serializedCacheValue = (byte[]) readDataField(1, cacheValueSize); // passing "1" ==> don't deserialize the cacheValue
            }
        }

        //if (this.bHasCacheValue) {
        //    traceDebug("readEntry2()", "cacheName=" + this.htoddc.cacheName + " key=" + key + " dataSize=" + dataSize + " valueSize=" + valueSize + " cacheValueSize=" + cacheValueSize + " expiration=" + expiration);
        //}

        //
        // Build the entry
        //
        htEntry.copy(location, first_created, key, value, next, previous,
                     header.tablesize(tableid), tableid, valueSize,
                     expiration, validatorExpiration, dataSize,
                     serializedCacheValue, cacheValueSize, cacheValueHashcode,
                     isAliasId, isValidHashcodeForValue); // LI4337-17
        return htEntry;
    }