|
@@ -46,12 +46,16 @@ import cs.NativeArray;
|
|
private var nOccupied:Int;
|
|
private var nOccupied:Int;
|
|
private var upperBound:Int;
|
|
private var upperBound:Int;
|
|
|
|
|
|
|
|
+#if !no_map_cache
|
|
private var cachedKey:Int;
|
|
private var cachedKey:Int;
|
|
private var cachedIndex:Int;
|
|
private var cachedIndex:Int;
|
|
|
|
+#end
|
|
|
|
|
|
public function new() : Void
|
|
public function new() : Void
|
|
{
|
|
{
|
|
|
|
+#if !no_map_cache
|
|
cachedIndex = -1;
|
|
cachedIndex = -1;
|
|
|
|
+#end
|
|
}
|
|
}
|
|
|
|
|
|
public function set( key : Int, value : T ) : Void
|
|
public function set( key : Int, value : T ) : Void
|
|
@@ -135,17 +139,20 @@ import cs.NativeArray;
|
|
public function get( key : Int ) : Null<T>
|
|
public function get( key : Int ) : Null<T>
|
|
{
|
|
{
|
|
var idx = -1;
|
|
var idx = -1;
|
|
|
|
+#if !no_map_cache
|
|
if (cachedKey == key && ( (idx = cachedIndex) != -1 ))
|
|
if (cachedKey == key && ( (idx = cachedIndex) != -1 ))
|
|
{
|
|
{
|
|
return vals[idx];
|
|
return vals[idx];
|
|
}
|
|
}
|
|
|
|
+#end
|
|
|
|
|
|
idx = lookup(key);
|
|
idx = lookup(key);
|
|
if (idx != -1)
|
|
if (idx != -1)
|
|
{
|
|
{
|
|
|
|
+#if !no_map_cache
|
|
cachedKey = key;
|
|
cachedKey = key;
|
|
cachedIndex = idx;
|
|
cachedIndex = idx;
|
|
-
|
|
|
|
|
|
+#end
|
|
return vals[idx];
|
|
return vals[idx];
|
|
}
|
|
}
|
|
|
|
|
|
@@ -155,17 +162,20 @@ import cs.NativeArray;
|
|
private function getDefault( key : Int, def : T ) : T
|
|
private function getDefault( key : Int, def : T ) : T
|
|
{
|
|
{
|
|
var idx = -1;
|
|
var idx = -1;
|
|
|
|
+#if !no_map_cache
|
|
if (cachedKey == key && ( (idx = cachedIndex) != -1 ))
|
|
if (cachedKey == key && ( (idx = cachedIndex) != -1 ))
|
|
{
|
|
{
|
|
return vals[idx];
|
|
return vals[idx];
|
|
}
|
|
}
|
|
|
|
+#end
|
|
|
|
|
|
idx = lookup(key);
|
|
idx = lookup(key);
|
|
if (idx != -1)
|
|
if (idx != -1)
|
|
{
|
|
{
|
|
|
|
+#if !no_map_cache
|
|
cachedKey = key;
|
|
cachedKey = key;
|
|
cachedIndex = idx;
|
|
cachedIndex = idx;
|
|
-
|
|
|
|
|
|
+#end
|
|
return vals[idx];
|
|
return vals[idx];
|
|
}
|
|
}
|
|
|
|
|
|
@@ -175,16 +185,20 @@ import cs.NativeArray;
|
|
public function exists( key : Int ) : Bool
|
|
public function exists( key : Int ) : Bool
|
|
{
|
|
{
|
|
var idx = -1;
|
|
var idx = -1;
|
|
|
|
+#if !no_map_cache
|
|
if (cachedKey == key && ( (idx = cachedIndex) != -1 ))
|
|
if (cachedKey == key && ( (idx = cachedIndex) != -1 ))
|
|
{
|
|
{
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+#end
|
|
|
|
|
|
idx = lookup(key);
|
|
idx = lookup(key);
|
|
if (idx != -1)
|
|
if (idx != -1)
|
|
{
|
|
{
|
|
|
|
+#if !no_map_cache
|
|
cachedKey = key;
|
|
cachedKey = key;
|
|
cachedIndex = idx;
|
|
cachedIndex = idx;
|
|
|
|
+#end
|
|
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@@ -195,7 +209,9 @@ import cs.NativeArray;
|
|
public function remove( key : Int ) : Bool
|
|
public function remove( key : Int ) : Bool
|
|
{
|
|
{
|
|
var idx = -1;
|
|
var idx = -1;
|
|
|
|
+#if !no_map_cache
|
|
if (! (cachedKey == key && ( (idx = cachedIndex) != -1 )))
|
|
if (! (cachedKey == key && ( (idx = cachedIndex) != -1 )))
|
|
|
|
+#end
|
|
{
|
|
{
|
|
idx = lookup(key);
|
|
idx = lookup(key);
|
|
}
|
|
}
|
|
@@ -204,9 +220,10 @@ import cs.NativeArray;
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
} else {
|
|
} else {
|
|
|
|
+#if !no_map_cache
|
|
if (cachedKey == key)
|
|
if (cachedKey == key)
|
|
cachedIndex = -1;
|
|
cachedIndex = -1;
|
|
-
|
|
|
|
|
|
+#end
|
|
if (!isEither(flags, idx))
|
|
if (!isEither(flags, idx))
|
|
{
|
|
{
|
|
setIsDelTrue(flags, idx);
|
|
setIsDelTrue(flags, idx);
|
|
@@ -253,9 +270,11 @@ import cs.NativeArray;
|
|
|
|
|
|
if (j != 0)
|
|
if (j != 0)
|
|
{ //rehashing is required
|
|
{ //rehashing is required
|
|
|
|
+#if !no_map_cache
|
|
//resetting cache
|
|
//resetting cache
|
|
cachedKey = 0;
|
|
cachedKey = 0;
|
|
cachedIndex = -1;
|
|
cachedIndex = -1;
|
|
|
|
+#end
|
|
|
|
|
|
j = -1;
|
|
j = -1;
|
|
var nBuckets = nBuckets, _keys = _keys, vals = vals, flags = flags;
|
|
var nBuckets = nBuckets, _keys = _keys, vals = vals, flags = flags;
|
|
@@ -438,8 +457,10 @@ private class IntMapKeyIterator<T> {
|
|
|
|
|
|
public function next():Int {
|
|
public function next():Int {
|
|
var ret = m._keys[i];
|
|
var ret = m._keys[i];
|
|
|
|
+#if !no_map_cache
|
|
m.cachedIndex = i;
|
|
m.cachedIndex = i;
|
|
m.cachedKey = ret;
|
|
m.cachedKey = ret;
|
|
|
|
+#end
|
|
i++;
|
|
i++;
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
@@ -471,4 +492,4 @@ private class IntMapValueIterator<T> {
|
|
public inline function next():T {
|
|
public inline function next():T {
|
|
return m.vals[i++];
|
|
return m.vals[i++];
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|