All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sirix.index.art.LeafNode Maven / Gradle / Ivy

Go to download

SirixDB is a hybrid on-disk and in-memory document oriented, versioned database system. It has a lightweight buffer manager, stores everything in a huge persistent and durable tree and allows efficient reconstruction of every revision. Furthermore, SirixDB implements change tracking, diffing and supports time travel queries.

There is a newer version: 0.11.0
Show newest version
package io.sirix.index.art;

import java.util.Arrays;
import java.util.Map;

/*
    currently we use what the paper mentions as "Single-value" leaves
 */
class LeafNode extends Node implements Map.Entry {
	private V value;

	// we have to save the keyBytes, because leaves are lazy expanded at times
	private final byte[] keyBytes;
	private final K key;

	LeafNode(byte[] keyBytes, K key, V value) {
		this.value = value;
		// defensive copy
		this.keyBytes = Arrays.copyOf(keyBytes, keyBytes.length);
		this.key = key;
	}

	public V setValue(V value) {
		V oldValue = this.value;
		this.value = value;
		return oldValue;
	}

	public V getValue() {
		return value;
	}

	byte[] getKeyBytes() {
		return keyBytes;
	}

	public K getKey() {
		return key;
	}

	/**
	 Dev note: first() is implemented to detect end of the SortedMap.firstKey()
	 */
	@Override
	public Node first() {
		return null;
	}

	@Override
	public Node firstOrLeaf() {
		return null;
	}

	/**
	 Dev note: last() is implemented to detect end of the SortedMap.lastKey()
	 */
	@Override
	public Node last() {
		return null;
	}

	/**
	 * Compares this Map.Entry with another Map.Entry.
	 * 

* Implemented per API documentation of {@link Map.Entry#equals(Object)} * * @param obj the object to compare to * @return true if equal key and value */ @Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (!(obj instanceof final Map.Entry other)) { return false; } return (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) && (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue())); } /** * Gets a hashCode compatible with the equals method. *

* Implemented per API documentation of {@link Map.Entry#hashCode()} * * @return a suitable hash code */ @Override public int hashCode() { return (getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode()); } @Override public String toString() { return key + "=" + value; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy