Adds a new cache entry. If an entry with the specified key already exists, it will be updated. @param key key @param count number of index hits @param offset offset to ID list @return cache entry
(final byte[] key, final int count, final long offset)
| 53 | * @return cache entry |
| 54 | */ |
| 55 | public IndexEntry add(final byte[] key, final int count, final long offset) { |
| 56 | final int hash = Token.hashCode(key); |
| 57 | rwl.writeLock().lock(); |
| 58 | |
| 59 | try { |
| 60 | purge(); |
| 61 | final int i = indexFor(hash, buckets.length); |
| 62 | BucketEntry current = buckets[i], prev = current; |
| 63 | while(current != null) { |
| 64 | final BucketEntry next = current.next; |
| 65 | final IndexEntry entry = current.get(); |
| 66 | if(entry == null) { |
| 67 | delete(i, current, prev, next); |
| 68 | } else if(current.hash == hash && Token.eq(entry.key, key)) { |
| 69 | update(entry, count, offset); |
| 70 | return entry; |
| 71 | } |
| 72 | prev = current; |
| 73 | current = next; |
| 74 | } |
| 75 | |
| 76 | final IndexEntry entry = new IndexEntry(key, count, offset); |
| 77 | add(i, hash, entry); |
| 78 | return entry; |
| 79 | } finally { |
| 80 | rwl.writeLock().unlock(); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Deletes a cached entry. |