Move the CRC computation to its own method so that we can use it elsewhere.
git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@1088 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -87,9 +87,7 @@ public abstract class Stat
|
|||||||
public static int initType (Type type, Stat prototype)
|
public static int initType (Type type, Stat prototype)
|
||||||
{
|
{
|
||||||
// compute a code for this stat using the CRC32 hash of its name
|
// compute a code for this stat using the CRC32 hash of its name
|
||||||
_crc.reset();
|
int code = crc32(type.name());
|
||||||
_crc.update(type.name().getBytes());
|
|
||||||
int code = (int)_crc.getValue();
|
|
||||||
|
|
||||||
// make sure the code does not collide
|
// make sure the code does not collide
|
||||||
if (_codeToType.containsKey(code)) {
|
if (_codeToType.containsKey(code)) {
|
||||||
@@ -106,6 +104,16 @@ public abstract class Stat
|
|||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes and returns the CRC32 hash of the specified string.
|
||||||
|
*/
|
||||||
|
public static int crc32 (String string)
|
||||||
|
{
|
||||||
|
_crc.reset();
|
||||||
|
_crc.update(string.getBytes());
|
||||||
|
return (int)_crc.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the type of this statistic.
|
* Returns the type of this statistic.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user