Exemplo n.º 1
0
 protected long indexHeaderChecksum() {
   long ret = 0;
   for (long offset = 0; offset < IO_USER_START; offset += 8) {
     if (offset == IO_INDEX_SUM) continue;
     long indexVal = index.getLong(offset);
     ret += indexVal + DataIO.longHash(indexVal + offset);
   }
   return ret;
 }
Exemplo n.º 2
0
  @Test
  public void commitChecksum() {
    WriteAheadLog wal = new WriteAheadLog(null);
    wal.open(WriteAheadLog.NOREPLAY);
    wal.startNextFile();

    wal.walPutLong(111L, 1000);
    wal.commit();
    long offset1 = wal.fileOffset - 5;
    int checksum1 = DataIO.longHash(wal.curVol.hash(16, offset1 - 16, 111L));

    assertEquals(checksum1, wal.curVol.getInt(offset1 + 1));
    wal.walPutLong(111L, 1000);
    wal.commit();
    long offset2 = wal.fileOffset - 5;
    int checksum2 =
        checksum1 + DataIO.longHash(wal.curVol.hash(offset1 + 5, offset2 - offset1 - 5, 111L));
    assertEquals(checksum2, wal.curVol.getInt(offset2 + 1));
  }
Exemplo n.º 3
0
 /**
  * @return the previous value associated with the specified key, or <tt>null</tt> if there was no
  *     mapping for the key
  * @throws NullPointerException if the specified key or value is null
  */
 public V replace(long key, V value) {
   if (value == null) throw new NullPointerException();
   final int hash = DataIO.longHash(key ^ hashSalt);
   return segmentFor(hash).replace(key, hash, value);
 }
Exemplo n.º 4
0
 /** @throws NullPointerException if any of the arguments are null */
 public boolean replace(long key, V oldValue, V newValue) {
   if (oldValue == null || newValue == null) throw new NullPointerException();
   final int hash = DataIO.longHash(key ^ hashSalt);
   return segmentFor(hash).replace(key, hash, oldValue, newValue);
 }
Exemplo n.º 5
0
 /** @throws NullPointerException if the specified key is null */
 public boolean remove(long key, Object value) {
   final int hash = DataIO.longHash(key ^ hashSalt);
   return value != null && segmentFor(hash).remove(key, hash, value) != null;
 }
Exemplo n.º 6
0
 /**
  * Removes the key (and its corresponding value) from this map. This method does nothing if the
  * key is not in the map.
  *
  * @param key the key that needs to be removed
  * @return the previous value associated with <tt>key</tt>, or <tt>null</tt> if there was no
  *     mapping for <tt>key</tt>
  * @throws NullPointerException if the specified key is null
  */
 @Override
 public V remove(long key) {
   final int hash = DataIO.longHash(key ^ hashSalt);
   return segmentFor(hash).remove(key, hash, null);
 }
Exemplo n.º 7
0
 /**
  * @return the previous value associated with the specified key, or <tt>null</tt> if there was no
  *     mapping for the key
  * @throws NullPointerException if the specified key or value is null
  */
 public V putIfAbsent(long key, V value) {
   if (value == null) throw new NullPointerException();
   final int hash = DataIO.longHash(key ^ hashSalt);
   return segmentFor(hash).put(key, hash, value, true);
 }
Exemplo n.º 8
0
 /**
  * Tests if the specified object is a key in this table.
  *
  * @param key possible key
  * @return <tt>true</tt> if and only if the specified object is a key in this table, as determined
  *     by the <tt>equals</tt> method; <tt>false</tt> otherwise.
  * @throws NullPointerException if the specified key is null
  */
 public boolean containsKey(long key) {
   final int hash = DataIO.longHash(key ^ hashSalt);
   return segmentFor(hash).containsKey(key, hash);
 }
Exemplo n.º 9
0
 /**
  * Returns the value to which the specified key is mapped, or {@code null} if this map contains no
  * mapping for the key.
  *
  * <p>More formally, if this map contains a mapping from a key {@code k} to a value {@code keys}
  * such that {@code key.equals(k)}, then this method returns {@code keys}; otherwise it returns
  * {@code null}. (There can be at most one such mapping.)
  *
  * @throws NullPointerException if the specified key is null
  */
 @Override
 public V get(long key) {
   final int hash = DataIO.longHash(key ^ hashSalt);
   return segmentFor(hash).get(key, hash);
 }