Skip to content

Commit

Permalink
putChar implementations for Murmur3
Browse files Browse the repository at this point in the history
  • Loading branch information
oertl committed Jul 31, 2024
1 parent 0ca18cb commit e1d52cd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/main/java/com/dynatrace/hash4j/hashing/Murmur3_128.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,15 @@ public HashStream128 putByte(byte b) {

@Override
public HashStream128 putShort(short v) {
final long l = v & 0xFFFFL;
return putTwoBytes(v & 0xFFFFL);
}

@Override
public HashStream128 putChar(char v) {
return putTwoBytes(v);
}

private HashStream128 putTwoBytes(long l) {
buffer1 |= l << bitCount;
if ((bitCount & 0x30L) == 0x30L) {
if ((bitCount & 0x40L) != 0) {
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/dynatrace/hash4j/hashing/Murmur3_32.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,16 @@ public HashStream32 putByte(byte b) {

@Override
public HashStream32 putShort(short v) {
buffer |= (v & 0xFFFFL) << shift;
return putTwoBytes(v & 0xFFFFL);
}

@Override
public HashStream32 putChar(char v) {
return putTwoBytes(v);
}

private HashStream32 putTwoBytes(long v) {
buffer |= v << shift;
shift += 16;
length += 2;
if (shift >= 32) {
Expand Down

0 comments on commit e1d52cd

Please sign in to comment.