public final class DbKey extends java.lang.Object implements java.lang.Comparable<DbKey>
It includes:
The binary layout of the database key is the following:
Offset: 0 1 … 32 33 34 Database key: | node type | 32-byte long user key | common prefix size |
Modifier and Type | Class and Description |
---|---|
static class |
DbKey.Type
Type of the node in a Merkle-Patricia tree.
|
Modifier and Type | Field and Description |
---|---|
static int |
DB_KEY_SIZE
Size of the database key in bytes.
|
static int |
KEY_SIZE
Size of the user key in bytes.
|
static int |
KEY_SIZE_BITS
Size of the user key in bits.
|
Modifier and Type | Method and Description |
---|---|
DbKey |
commonPrefix(DbKey other)
Returns new branch DbKey (unless common prefix of two equals DbKeys is requested, in which
case this DbKey itself is returned), which is a common prefix of this and another DbKey.
|
int |
compareTo(DbKey other)
The following algorithm is used for comparison:
Try to find a first bit index at which this key is greater than the other key (i.e., a bit of
this key is 1 and the corresponding bit of the other key is 0), and vice versa.
|
boolean |
equals(java.lang.Object o) |
static DbKey |
fromBytes(byte[] rawDbKey)
Creates a database key.
|
byte[] |
getKeySlice()
Returns the key slice.
|
DbKey.Type |
getNodeType()
Returns the type of the Merkle-Patricia tree node corresponding to this database key.
|
int |
getNumSignificantBits()
Returns the number of significant bits in the key slice.
|
byte[] |
getRawDbKey() |
int |
hashCode() |
boolean |
isPrefixOf(DbKey other)
Returns true if this
DbKey is a prefix of that DbKey . |
KeyBitSet |
keyBits()
Returns a key as a bit set.
|
static DbKey |
newBranchKey(byte[] keySlice,
int numSignificantBits)
Creates a new branch database key.
|
static DbKey |
newLeafKey(byte[] keySlice)
Given key as a byte array, returns new leaf DbKey.
|
static DbKey |
newLeafKey(com.google.protobuf.ByteString key)
Given key as a ByteString, returns new leaf DbKey.
|
public static final int KEY_SIZE
public static final int KEY_SIZE_BITS
public static final int DB_KEY_SIZE
public static DbKey fromBytes(byte[] rawDbKey)
rawDbKey
- a raw database key, as used in the underlying storagejava.lang.NullPointerException
- if the key is nulljava.lang.IllegalArgumentException
- if the specified database key is not validpublic static DbKey newLeafKey(com.google.protobuf.ByteString key)
public static DbKey newLeafKey(byte[] keySlice)
public static DbKey newBranchKey(byte[] keySlice, int numSignificantBits)
keySlice
- key as a byte array, must be 32-byte longnumSignificantBits
- the number of significant bits in the key (= the prefix size)java.lang.IllegalArgumentException
- if key has invalid length or contains set bits
after the prefix; if numSignificantBits is not in range [0, 255]public DbKey.Type getNodeType()
public byte[] getKeySlice()
KEY_SIZE
, but the number of significant
bits is equal to the getNumSignificantBits()
.public int getNumSignificantBits()
public byte[] getRawDbKey()
public KeyBitSet keyBits()
public DbKey commonPrefix(DbKey other)
public boolean isPrefixOf(DbKey other)
DbKey
is a prefix of that DbKey
.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public int compareTo(DbKey other)
compareTo
in interface java.lang.Comparable<DbKey>
Copyright © 2018 Exonum. All rights reserved.