|
@@ -46,8 +46,10 @@ import cs.NativeArray;
|
|
|
private var nOccupied:Int;
|
|
|
private var upperBound:Int;
|
|
|
|
|
|
+#if !no_map_cache
|
|
|
private var cachedKey:String;
|
|
|
private var cachedIndex:Int;
|
|
|
+#end
|
|
|
|
|
|
#if DEBUG_HASHTBL
|
|
|
private var totalProbes:Int;
|
|
@@ -58,7 +60,9 @@ import cs.NativeArray;
|
|
|
|
|
|
public function new() : Void
|
|
|
{
|
|
|
+#if !no_map_cache
|
|
|
cachedIndex = -1;
|
|
|
+#end
|
|
|
}
|
|
|
|
|
|
public function set( key : String, value : T ) : Void
|
|
@@ -122,8 +126,10 @@ import cs.NativeArray;
|
|
|
vals[x] = value;
|
|
|
}
|
|
|
|
|
|
+#if !no_map_cache
|
|
|
cachedIndex = x;
|
|
|
cachedKey = key;
|
|
|
+#end
|
|
|
}
|
|
|
|
|
|
@:final private function lookup( key : String ) : Int
|
|
@@ -189,8 +195,10 @@ import cs.NativeArray;
|
|
|
if (j != 0)
|
|
|
{ //rehashing is required
|
|
|
//resetting cache
|
|
|
+#if !no_map_cache
|
|
|
cachedKey = null;
|
|
|
cachedIndex = -1;
|
|
|
+#end
|
|
|
|
|
|
j = -1;
|
|
|
var nBuckets = nBuckets, _keys = _keys, vals = vals, hashes = hashes;
|
|
@@ -263,17 +271,19 @@ import cs.NativeArray;
|
|
|
public function get( key : String ) : Null<T>
|
|
|
{
|
|
|
var idx = -1;
|
|
|
+#if !no_map_cache
|
|
|
if (cachedKey == key && ( (idx = cachedIndex) != -1 ))
|
|
|
{
|
|
|
return vals[idx];
|
|
|
}
|
|
|
-
|
|
|
+#end
|
|
|
idx = lookup(key);
|
|
|
if (idx != -1)
|
|
|
{
|
|
|
+#if !no_map_cache
|
|
|
cachedKey = key;
|
|
|
cachedIndex = idx;
|
|
|
-
|
|
|
+#end
|
|
|
return vals[idx];
|
|
|
}
|
|
|
|
|
@@ -283,16 +293,20 @@ import cs.NativeArray;
|
|
|
private function getDefault( key : String, def : T ) : T
|
|
|
{
|
|
|
var idx = -1;
|
|
|
+#if !no_map_cache
|
|
|
if (cachedKey == key && ( (idx = cachedIndex) != -1 ))
|
|
|
{
|
|
|
return vals[idx];
|
|
|
}
|
|
|
+#end
|
|
|
|
|
|
idx = lookup(key);
|
|
|
if (idx != -1)
|
|
|
{
|
|
|
+#if !no_map_cache
|
|
|
cachedKey = key;
|
|
|
cachedIndex = idx;
|
|
|
+#end
|
|
|
|
|
|
return vals[idx];
|
|
|
}
|
|
@@ -303,17 +317,20 @@ import cs.NativeArray;
|
|
|
public function exists( key : String ) : Bool
|
|
|
{
|
|
|
var idx = -1;
|
|
|
+#if !no_map_cache
|
|
|
if (cachedKey == key && ( (idx = cachedIndex) != -1 ))
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
+#end
|
|
|
|
|
|
idx = lookup(key);
|
|
|
if (idx != -1)
|
|
|
{
|
|
|
+#if !no_map_cache
|
|
|
cachedKey = key;
|
|
|
cachedIndex = idx;
|
|
|
-
|
|
|
+#end
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -323,7 +340,9 @@ import cs.NativeArray;
|
|
|
public function remove( key : String ) : Bool
|
|
|
{
|
|
|
var idx = -1;
|
|
|
+#if !no_map_cache
|
|
|
if (! (cachedKey == key && ( (idx = cachedIndex) != -1 )))
|
|
|
+#end
|
|
|
{
|
|
|
idx = lookup(key);
|
|
|
}
|
|
@@ -332,9 +351,10 @@ import cs.NativeArray;
|
|
|
{
|
|
|
return false;
|
|
|
} else {
|
|
|
+#if !no_map_cache
|
|
|
if (cachedKey == key)
|
|
|
cachedIndex = -1;
|
|
|
-
|
|
|
+#end
|
|
|
hashes[idx] = FLAG_DEL;
|
|
|
_keys[idx] = null;
|
|
|
vals[idx] = null;
|
|
@@ -471,8 +491,10 @@ private class StringMapKeyIterator<T> {
|
|
|
|
|
|
public function next():String {
|
|
|
var ret = m._keys[i];
|
|
|
+#if !no_map_cache
|
|
|
m.cachedIndex = i;
|
|
|
m.cachedKey = ret;
|
|
|
+#end
|
|
|
i++;
|
|
|
return ret;
|
|
|
}
|