|
@@ -1,12 +1,10 @@
|
|
-package haxe.lang;
|
|
|
|
-
|
|
|
|
@:native('haxe.lang.FieldLookup')
|
|
@:native('haxe.lang.FieldLookup')
|
|
-@:static private class FieldLookup
|
|
|
|
|
|
+@:static private class FieldLookup
|
|
{
|
|
{
|
|
|
|
|
|
@:private private static var fieldIds:Array<Int>;
|
|
@:private private static var fieldIds:Array<Int>;
|
|
@:private private static var fields:Array<String>;
|
|
@:private private static var fields:Array<String>;
|
|
-
|
|
|
|
|
|
+
|
|
//s cannot be null here
|
|
//s cannot be null here
|
|
private static inline function doHash(s:String):Int
|
|
private static inline function doHash(s:String):Int
|
|
{
|
|
{
|
|
@@ -15,17 +13,17 @@ package haxe.lang;
|
|
{
|
|
{
|
|
acc = (( 223 * (acc >> 1) + s.charCodeAt(i) ) << 1);
|
|
acc = (( 223 * (acc >> 1) + s.charCodeAt(i) ) << 1);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
return acc >>> 1; //always positive
|
|
return acc >>> 1; //always positive
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static function lookupHash(key:Int):String
|
|
public static function lookupHash(key:Int):String
|
|
{
|
|
{
|
|
//start of binary search algorithm
|
|
//start of binary search algorithm
|
|
var ids = fieldIds;
|
|
var ids = fieldIds;
|
|
var min = 0;
|
|
var min = 0;
|
|
var max = ids.length;
|
|
var max = ids.length;
|
|
-
|
|
|
|
|
|
+
|
|
while (min < max)
|
|
while (min < max)
|
|
{
|
|
{
|
|
var mid = Std.int(min + (max - min) / 2); //overflow safe
|
|
var mid = Std.int(min + (max - min) / 2); //overflow safe
|
|
@@ -42,18 +40,18 @@ package haxe.lang;
|
|
//if not found, it's definately an error
|
|
//if not found, it's definately an error
|
|
throw "Field not found for hash " + key;
|
|
throw "Field not found for hash " + key;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static function hash(s:String):Int
|
|
public static function hash(s:String):Int
|
|
{
|
|
{
|
|
if (s == null) return 0;
|
|
if (s == null) return 0;
|
|
-
|
|
|
|
|
|
+
|
|
var key = doHash(s);
|
|
var key = doHash(s);
|
|
-
|
|
|
|
|
|
+
|
|
//start of binary search algorithm
|
|
//start of binary search algorithm
|
|
var ids = fieldIds;
|
|
var ids = fieldIds;
|
|
var min = 0;
|
|
var min = 0;
|
|
var max = ids.length;
|
|
var max = ids.length;
|
|
-
|
|
|
|
|
|
+
|
|
while (min < max)
|
|
while (min < max)
|
|
{
|
|
{
|
|
var mid = Std.int(min + (max - min) / 2); //overflow safe
|
|
var mid = Std.int(min + (max - min) / 2); //overflow safe
|
|
@@ -75,12 +73,12 @@ package haxe.lang;
|
|
fields.insert(min, s);
|
|
fields.insert(min, s);
|
|
return key;
|
|
return key;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static function findHash(hash:Int, hashs:Array<Int>):Int
|
|
public static function findHash(hash:Int, hashs:Array<Int>):Int
|
|
{
|
|
{
|
|
var min = 0;
|
|
var min = 0;
|
|
var max = hashs.length;
|
|
var max = hashs.length;
|
|
-
|
|
|
|
|
|
+
|
|
while (min < max)
|
|
while (min < max)
|
|
{
|
|
{
|
|
var mid = Std.int((max + min) / 2); //overflow safe
|
|
var mid = Std.int((max + min) / 2); //overflow safe
|
|
@@ -97,5 +95,5 @@ package haxe.lang;
|
|
//if not found, return a negative value of where it should be inserted
|
|
//if not found, return a negative value of where it should be inserted
|
|
return ~min;
|
|
return ~min;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|