Skip to content
This repository has been archived by the owner on Jul 7, 2020. It is now read-only.

Make MurmurHash of Strings independent of default encoding #85

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/main/java/com/clearspring/analytics/hash/MurmurHash.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.clearspring.analytics.hash;

import java.nio.charset.Charset;


/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
Expand Down Expand Up @@ -45,7 +48,7 @@ public static int hash(Object o) {
return hashLong(Float.floatToRawIntBits((Float) o));
}
if (o instanceof String) {
return hash(((String) o).getBytes());
return hash(((String) o).getBytes(Charset.forName("UTF8")));
}
if (o instanceof byte[]) {
return hash((byte[]) o);
Expand Down Expand Up @@ -136,7 +139,7 @@ public static long hash64(Object o) {
if (o == null) {
return 0l;
} else if (o instanceof String) {
final byte[] bytes = ((String) o).getBytes();
final byte[] bytes = ((String) o).getBytes(Charset.forName("UTF8"));
return hash64(bytes, bytes.length);
} else if (o instanceof byte[]) {
final byte[] bytes = (byte[]) o;
Expand Down