public int addLabel(CategoryPath label, int hash, int cid) { int bucketIndex = indexFor(hash, this.capacity); for (Entry e = this.entries[bucketIndex]; e != null; e = e.next) { if (e.hash == hash && CategoryPathUtils.equalsToSerialized(label, labelRepository, e.offset)) { return e.cid; } } // new string; add to label repository int offset = labelRepository.length(); CategoryPathUtils.serialize(label, labelRepository); addEntry(offset, cid, hash, bucketIndex); return cid; }
public int get(CategoryPath label, int hash) { int bucketIndex = indexFor(hash, this.capacity); Entry e = this.entries[bucketIndex]; while (e != null && !(hash == e.hash && CategoryPathUtils.equalsToSerialized(label, labelRepository, e.offset))) { e = e.next; } if (e == null) { return LabelToOrdinal.INVALID_ORDINAL; } return e.cid; }