git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4296 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-07-29 01:10:15 +00:00
parent 3d7c12a5d1
commit 47a8a27a4e
4 changed files with 36 additions and 57 deletions
+5 -22
View File
@@ -6,6 +6,7 @@ import com.threerings.util.ArrayIterator;
import com.threerings.util.Equalable;
import com.threerings.util.Iterator;
import com.threerings.util.StringBuilder;
import com.threerings.util.Util;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
@@ -70,7 +71,7 @@ public class DSet
{
// o(n) for now
for each (var entry :DSet_Entry in _entries) {
if (isSameKey(key, entry.getKey())) {
if (Util.equals(key, entry.getKey())) {
return entry;
}
}
@@ -157,7 +158,7 @@ public class DSet
// o(n) for now
for (var ii :int = 0; ii < _entries.length; ii++) {
var entry :DSet_Entry = _entries[ii];
if (isSameKey(key, entry.getKey())) {
if (Util.equals(key, entry.getKey())) {
_entries.splice(ii, 1);
return entry;
}
@@ -180,7 +181,7 @@ public class DSet
var key :Object = elem.getKey();
for (var ii :int = 0; ii < _entries.length; ii++) {
var entry :DSet_Entry = _entries[ii];
if (isSameKey(key, entry.getKey())) {
if (Util.equals(key, entry.getKey())) {
_entries[ii] = elem;
return entry; // return the old entry
}
@@ -188,23 +189,6 @@ public class DSet
return null;
}
/**
* Internal function to determine whether a key matches the key for
* an existing entry.
*/
private function isSameKey (key :Object, otherKey :Object) :Boolean
{
if (ObjectUtil.isSimple(key)) {
return (key === otherKey);
} else if (key is Equalable) {
return (key as Equalable).equals(otherKey);
} else {
throw new Error("Element key is neither simple or Equalable");
}
}
/**
* Generates a string representation of this set instance.
*/
@@ -235,7 +219,6 @@ public class DSet
}
/** The entries of the set (in a sparse array). */
protected var _entries :TypedArray =
new TypedArray("[Lcom.threerings.presents.dobj.DSet$Entry;");
protected var _entries :TypedArray = TypedArray.create(DSet_Entry);
}
}
+7 -21
View File
@@ -1,5 +1,7 @@
package com.threerings.presents.dobj {
import com.threerings.util.ArrayUtil;
import com.threerings.io.Streamable;
import com.threerings.io.ObjectInputStream;
@@ -22,7 +24,7 @@ public class OidList
*/
public function OidList ()
{
_oids = new TypedArray("[I");
_oids = TypedArray.create(int);
}
/**
@@ -43,10 +45,8 @@ public class OidList
public function add (oid :int) :Boolean
{
// check for existence
for (var ii :int = 0; ii < _oids.length; ii++) {
if (_oids[ii] == oid) {
return false;
}
if (ArrayUtil.contains(_oids, oid)) {
return false;
}
// add the oid
@@ -63,15 +63,7 @@ public class OidList
public function remove (oid :int) :Boolean
{
// scan for the oid in question
for (var ii :int = 0; ii < _oids.length; ii++) {
if (_oids[ii] == oid) {
// shift the rest of the list back one
_oids.splice(ii, 1);
return true;
}
}
return false;
return ArrayUtil.removeFirst(_oids, oid);
}
/**
@@ -79,13 +71,7 @@ public class OidList
*/
public function contains (oid :int) :Boolean
{
for (var ii :int = 0; ii < _oids.length; ii++) {
if (_oids[ii] == oid) {
return true;
}
}
return false;
return ArrayUtil.contains(_oids, oid);
}
/**