Skip to content

Commit

Permalink
Merge pull request #43 from sanekas/task/unsafe_primitives_reading
Browse files Browse the repository at this point in the history
Reading primitives unsafe (natively through ByteBuffer API)
  • Loading branch information
ak0rz committed Mar 13, 2019
2 parents c82df86 + 26822ce commit 1f91a9e
Show file tree
Hide file tree
Showing 34 changed files with 1,757 additions and 68 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Please keep the list sorted.

Alexander Sergeev <[email protected]>
Andrey Korzinev <[email protected]>
Irina Kamalova <[email protected]>
Svyatoslav Demidov <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface DocumentProvider {
/**
* Get {@code document} document {@code fieldName} field value.
*
* The field must be sortable.
* The field must be sortable, stored or full.
*
* @see com.yandex.yoctodb.mutable.DocumentBuilder.IndexOption#SORTABLE
* @see com.yandex.yoctodb.mutable.DocumentBuilder.IndexOption#FULL
Expand All @@ -50,4 +50,89 @@ Buffer getFieldValue(
int document,
@NotNull
String fieldName);

/**
* Get {@code document} document {@code fieldName} field value as long.
*
* The field must be sortable, stored or full.
*
* @see com.yandex.yoctodb.mutable.DocumentBuilder.IndexOption#SORTABLE
* @see com.yandex.yoctodb.mutable.DocumentBuilder.IndexOption#FULL
* @see com.yandex.yoctodb.mutable.DocumentBuilder.IndexOption#STORED
* @param document document index
* @param fieldName field name
* @return document field value as long
*/
long getLongValue(
int document,
@NotNull
String fieldName);

/**
* Get {@code document} document {@code fieldName} field value as int.
*
* The field must be sortable, stored or full.
*
* @see com.yandex.yoctodb.mutable.DocumentBuilder.IndexOption#SORTABLE
* @see com.yandex.yoctodb.mutable.DocumentBuilder.IndexOption#FULL
* @see com.yandex.yoctodb.mutable.DocumentBuilder.IndexOption#STORED
* @param document document index
* @param fieldName field name
* @return document field value as int
*/
int getIntValue(
int document,
@NotNull
String fieldName);

/**
* Get {@code document} document {@code fieldName} field value as short.
*
* The field must be sortable, stored or full.
*
* @param document document index
* @param fieldName field name
* @return document field value as short
*/
short getShortValue(
int document,
@NotNull
String fieldName
);

/**
* Get {@code document} document {@code fieldName} field value as char.
*
* The field must be sortable, stored or full.
*
* @see com.yandex.yoctodb.mutable.DocumentBuilder.IndexOption#SORTABLE
* @see com.yandex.yoctodb.mutable.DocumentBuilder.IndexOption#FULL
* @see com.yandex.yoctodb.mutable.DocumentBuilder.IndexOption#STORED
* @param document document index
* @param fieldName field name
* @return document field value as char
*/
char getCharValue(
int document,
@NotNull
String fieldName
);

/**
* Get {@code document} document {@code fieldName} field value as byte.
*
* The field must be sortable, stored or full.
*
* @see com.yandex.yoctodb.mutable.DocumentBuilder.IndexOption#SORTABLE
* @see com.yandex.yoctodb.mutable.DocumentBuilder.IndexOption#FULL
* @see com.yandex.yoctodb.mutable.DocumentBuilder.IndexOption#STORED
* @param document document index
* @param fieldName field name
* @return document field value as byte
*/
byte getByteValue(
int document,
@NotNull
String fieldName
);
}
40 changes: 40 additions & 0 deletions core/src/main/java/com/yandex/yoctodb/immutable/StoredIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,44 @@ public interface StoredIndex extends Index {
*/
@NotNull
Buffer getStoredValue(int document);

/**
* Get stored value as long by document ID
*
* @param document document ID
* @return stored value as long
*/
long getLongValue(int document);

/**
* Get stored value as int by document ID
*
* @param document document ID
* @return stored value as int
*/
int getIntValue(int document);

/**
* Get stored value as short by document ID
*
* @param document document ID
* @return stored value as short
*/
short getShortValue(int document);

/**
* Get stored value as char by document ID
*
* @param document document ID
* @return stored value as char
*/
char getCharValue(int document);

/**
* Get stored value as byte by document ID
*
* @param document document ID
* @return stored value as byte
*/
byte getByteValue(int document);
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,22 @@ public DocumentBuilder withField(
@Override
public DocumentBuilder withField(
@NotNull
final
String name,
final String name,
final long value,
@NotNull
final IndexOption index) {
return withField(name, UnsignedByteArrays.from(value), index, IndexType.FIXED_LENGTH);
}

public DocumentBuilder withField(
@NotNull
final String name,
final char value,
@NotNull
final IndexOption index) {
return withField(name, UnsignedByteArrays.from(value), index, IndexType.FIXED_LENGTH);
}

@NotNull
@Override
public DocumentBuilder withField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ DocumentBuilder withField(
@NotNull
IndexOption index);

@NotNull
DocumentBuilder withField(
@NotNull
String name,
char c,
@NotNull
IndexOption index
);

@NotNull
DocumentBuilder withField(
@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public static UnsignedByteArray from(final int i) {
return from(Ints.toByteArray(i ^ Integer.MIN_VALUE));
}

@NotNull
public static UnsignedByteArray from(final char c) {
return from(Chars.toByteArray(c));
}

public static int toInt(
@NotNull
final UnsignedByteArray bytes) {
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/com/yandex/yoctodb/util/buf/Buffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ public byte[] toByteArray() {

public abstract long getLong(long index);

public abstract char getChar();

public abstract char getChar(long index);

public abstract short getShort();

public abstract short getShort(long index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ public long getLong(final long index) {
return delegate.getLong((int) index);
}

@Override
public char getChar() {
return delegate.getChar();
}

@Override
public char getChar(long index) {
assert index <= Integer.MAX_VALUE;

return delegate.getChar((int) index);
}

@Override
public short getShort() {
return delegate.getShort();
Expand Down
Loading

0 comments on commit 1f91a9e

Please sign in to comment.