MCPcopy Create free account
hub / github.com/BaseXdb/basex / add

Method add

basex-core/src/main/java/org/basex/index/IndexCache.java:55–82  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers

nothing calls this directly

Calls 10

hashCodeMethod · 0.95
purgeMethod · 0.95
indexForMethod · 0.95
deleteMethod · 0.95
eqMethod · 0.95
updateMethod · 0.95
rehashMethod · 0.95
writeLockMethod · 0.80
getMethod · 0.65
lockMethod · 0.45

Tested by

no test coverage detected