@@ -235,26 +235,26 @@ public ArrayMemory checkCopied() {
235235 public static Object toKey (Memory key ) {
236236 switch (key .type ) {
237237 case STRING : {
238- String key1 = key .toString ();
239- Memory number = StringMemory .toLong (key1 );
240- if (number == null )
241- return key1 ;
242- else
243- return number ;
238+ if (((StringMemory )key ).canBeConvertedToLong ()) {
239+ return StringMemory .toLong (key .toString ()).toLong ();
240+ } else {
241+ return key .toString ();
242+ }
244243 }
245244 case INT :
246- return key ;
245+ case DOUBLE :
246+ return key .toLong ();
247247 case NULL :
248248 return Memory .CONST_EMPTY_STRING ;
249249 case REFERENCE :
250250 return toKey (key .toValue ());
251251 default :
252- return LongMemory .valueOf (key .toLong ( ));
252+ return toKey ( StringMemory .valueOf (key .toString () ));
253253 }
254254 }
255255
256256 public boolean containsLongKey (long key ) {
257- return containsKey (LongMemory . valueOf ( key ) );
257+ return containsKey (key );
258258 }
259259
260260 public boolean containsKey (Object key ) {
@@ -273,10 +273,10 @@ public boolean containsKey(Object key) {
273273 private void convertToMap () {
274274 map = new ArrayMemoryMap ();
275275 if (_list != null && !_list .isEmpty ()) {
276- int i = 0 ;
276+ long i = 0 ;
277277 for (ReferenceMemory memory : _list ) {
278278 if (memory != null ) {
279- map .put (LongMemory . valueOf ( i ) , memory .getValue ());
279+ map .put (i , memory .getValue ());
280280 }
281281 i ++;
282282 }
@@ -343,8 +343,8 @@ public ReferenceMemory getByScalarOrCreate(Object sKey) {
343343
344344 public ReferenceMemory getByScalar (Object key ) {
345345 if (_list != null ) {
346- if (key instanceof Memory ) {
347- int index = (int ) (( Memory ) key ).toLong ();
346+ if (key instanceof Long ) {
347+ int index = (( Long ) key ).intValue ();
348348 if (index >= 0 && index < _list .size ()) {
349349 return _list .get (index );
350350 } else
@@ -396,7 +396,7 @@ public ReferenceMemory add(Memory value) {
396396 getList ().add (ref );
397397 size ++;
398398 } else {
399- ref = put (LongMemory . valueOf ( ++lastLongIndex ) , value );
399+ ref = put (++lastLongIndex , value );
400400 }
401401
402402 return ref ;
@@ -431,7 +431,7 @@ public void merge(ArrayMemory array, boolean recursive, Set<Integer> done) {
431431 } else {
432432 for (Map .Entry <Object , Memory > entry : array .map .entrySet ()) {
433433 Object key = entry .getKey ();
434- if (key instanceof LongMemory ) {
434+ if (key instanceof Long ) {
435435 add (entry .getValue ().toImmutable ());
436436 } else {
437437 Memory value = entry .getValue ();
@@ -466,10 +466,10 @@ public void merge(ArrayMemory array, boolean recursive, Set<Integer> done) {
466466
467467 public void putAll (ArrayMemory array ) {
468468 if (array .map == null ) {
469- int i = 0 ;
469+ long i = 0 ;
470470 for (ReferenceMemory memory : array .getList ()) {
471471 if (memory != null )
472- put (LongMemory . valueOf ( i ) , memory .toImmutable ());
472+ put (i , memory .toImmutable ());
473473 i ++;
474474 }
475475 } else {
@@ -488,10 +488,10 @@ public void putAll(ArrayMemory array) {
488488
489489 public void putAllRef (ArrayMemory array ) {
490490 if (array .map == null ) {
491- int i = 0 ;
491+ long i = 0 ;
492492 for (ReferenceMemory memory : array .getList ()) {
493493 if (memory != null )
494- put (LongMemory . valueOf ( i ) , memory );
494+ put (i , memory );
495495 i ++;
496496 }
497497 } else {
@@ -541,16 +541,21 @@ public ReferenceMemory put(Object key, IObject value) {
541541 return put (key , ObjectMemory .valueOf (value ));
542542 }
543543
544+ public ReferenceMemory put (long key , Memory value ) {
545+ return put ((Long ) key , value );
546+ }
547+
544548 public ReferenceMemory put (Object key , Memory value ) {
545- if (key instanceof LongMemory ) {
549+ if (key instanceof Long ) {
546550 ReferenceMemory mem = new ReferenceMemory (value );
547551
548- int index = (int ) ((LongMemory ) key ).value ;
549-
550- if (index > lastLongIndex )
551- lastLongIndex = index ;
552+ if ((Long ) key > lastLongIndex ) {
553+ lastLongIndex = (Long ) key ;
554+ }
552555
553556 if (map == null ) {
557+ int index = ((Number ) key ).intValue ();
558+
554559 int size = getList ().size ();
555560 if (index >= 0 ) {
556561 if (index < size ) {
@@ -618,14 +623,13 @@ else if (key instanceof String) {
618623 }
619624
620625 {
621- if (key instanceof Long )
622- key = LongMemory .valueOf ((Long ) key );
623- else if (key instanceof Integer )
624- key = LongMemory .valueOf ((Integer ) key );
625- else if (key instanceof String ) {
626+ if (key instanceof String ) {
626627 Memory tmp = StringMemory .toLong ((String ) key );
627- if (tmp != null )
628- key = tmp ;
628+ if (tmp != null ) {
629+ key = tmp .toLong ();
630+ }
631+ } else if (key instanceof Integer ) {
632+ key = ((Integer ) key ).longValue ();
629633 }
630634
631635 Memory memory = map .remove (key );
@@ -639,7 +643,7 @@ else if (key instanceof String) {
639643 public Memory remove (Memory key ) {
640644 Object _key = toKey (key );
641645 if (map == null ) {
642- int index = _key instanceof LongMemory ? (int ) key . toLong () : -1 ;
646+ int index = _key instanceof Long ? (( Long ) _key ). intValue () : -1 ;
643647 if (index < 0 || _list == null || index >= getList ().size ())
644648 return null ;
645649
@@ -813,8 +817,8 @@ public Memory peekKey() {
813817 return LongMemory .valueOf (size - 1 );
814818 else {
815819 Object key = map .lastKey ();
816- if (key instanceof Memory ) {
817- return ( Memory ) key ;
820+ if (key instanceof Long ) {
821+ return LongMemory . valueOf (( Long ) key ) ;
818822 } else if (key instanceof String ) {
819823 return StringMemory .valueOf (key .toString ());
820824 }
@@ -834,8 +838,8 @@ public Memory getRandomElementKey(Random rnd) {
834838 }
835839
836840 Object key = keys .next ();
837- if (key instanceof LongMemory )
838- return ( LongMemory ) key ;
841+ if (key instanceof Long )
842+ return LongMemory . valueOf (( long ) key ) ;
839843 else
840844 return new StringMemory ((String ) key );
841845 }
@@ -1168,13 +1172,13 @@ public Memory valueOfIndex(TraceInfo trace, Memory index) {
11681172
11691173 @ Override
11701174 public Memory valueOfIndex (TraceInfo trace , long index ) {
1171- Memory e = getByScalar (LongMemory . valueOf ( index ) );
1175+ Memory e = getByScalar (index );
11721176 return e == null ? UNDEFINED : e ;
11731177 }
11741178
11751179 @ Override
11761180 public Memory valueOfIndex (TraceInfo trace , double index ) {
1177- Memory e = getByScalar (LongMemory . valueOf (( long ) index ) );
1181+ Memory e = getByScalar (( long ) index );
11781182 return e == null ? UNDEFINED : e ;
11791183 }
11801184
@@ -1187,7 +1191,7 @@ public Memory valueOfIndex(TraceInfo trace, boolean index) {
11871191 @ Override
11881192 public Memory valueOfIndex (TraceInfo trace , String index ) {
11891193 Memory number = StringMemory .toLong (index );
1190- Memory e = number == null ? getByScalar (index ) : getByScalar (number );
1194+ Memory e = number == null ? getByScalar (index ) : getByScalar (number . toLong () );
11911195 return e == null ? UNDEFINED : e ;
11921196 }
11931197
@@ -1234,12 +1238,12 @@ public Memory refOfIndex(TraceInfo trace, Memory index) {
12341238 @ Override
12351239 public Memory refOfIndex (TraceInfo trace , long index ) {
12361240 checkCopied ();
1237- return getOrCreate ( LongMemory . valueOf ( index ) );
1241+ return getByScalarOrCreate ( index );
12381242 }
12391243
12401244 @ Override
12411245 public Memory refOfIndex (TraceInfo trace , double index ) {
1242- return refOfIndex (null , LongMemory . valueOf (( long ) index ) );
1246+ return refOfIndex (trace , ( long ) index );
12431247 }
12441248
12451249 @ Override
@@ -1252,7 +1256,7 @@ public Memory refOfIndex(TraceInfo trace, boolean index) {
12521256 public Memory refOfIndex (TraceInfo trace , String index ) {
12531257 checkCopied ();
12541258 Memory number = StringMemory .toLong (index );
1255- return number == null ? getByScalarOrCreate (index ) : getByScalarOrCreate (number );
1259+ return number == null ? getByScalarOrCreate (index ) : getByScalarOrCreate (number . toLong () );
12561260 }
12571261
12581262 @ Override
@@ -1402,7 +1406,7 @@ protected boolean prevValue() {
14021406 return false ;
14031407 } else {
14041408 cursor --;
1405- currentKey = LongMemory . valueOf (( long ) cursor ) ;
1409+ currentKey = ( long ) cursor ;
14061410 setCurrentValue (getList ().get (cursor ));
14071411 return true ;
14081412 }
@@ -1434,7 +1438,7 @@ protected boolean nextValue() {
14341438 return false ;
14351439 }
14361440
1437- currentKey = LongMemory . valueOf (( long ) cursor ) ;
1441+ currentKey = ( long ) cursor ;
14381442 setCurrentValue (getList ().get (cursor ));
14391443 cursor ++;
14401444 return true ;
0 commit comments