Keep a list of known objects in an Array as you loop through comparing
Object o1 with Object o2:
private var known:Array = [];
Then as you loop over complex objects, check whether you have seen the
first object (well, the one that you use to do the deep
comparison)before in which case you can assume that they are equal as
you're already testing the equality.
public function testEquality(o1:Object, o2:Object):Boolean
{
if (o1 instanceof String || o1 instanceof Number || o1 instanceof
Boolean)
{
return (o1 == o2); // Could alternative use strict equality here
to avoid casting between primitive types
}
...
else
{
// We have a complex type...
if (knownObject(o1))
{
return true; // We're already testing this object, return
true to avoid looping
}
rememberObject(o1);
if (o1 instanceof Array)
{
return testArrayEquality(o1, o2);
}
else
{
return testObjectEquality(o1, o2);
}
}
...
private function rememberObject(o:Object):Void
{
known.push(o);
}
private function knownObject(o1:Object):Boolean
{
for (var i:Number = 0; i < known.length; i++)
{
if (o1 === known[i])
{
return true;
}
}
return false;
}
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Stacy Young
Sent: Friday, December 09, 2005 5:46 PM
To: [email protected]
Subject: [flexcoders] Comparing complex objects
Wondering how others would go about comparing instances of complex
objects while avoiding circular references and having flash explode?
Thx!
Stace
------------------------ Yahoo! Groups Sponsor --------------------~-->
Most low income households are not online. Help bridge the digital
divide today!
http://us.click.yahoo.com/I258zB/QnQLAA/TtwFAA/nhFolB/TM
--------------------------------------------------------------------~->
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
------------------------ Yahoo! Groups Sponsor --------------------~-->
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/KIlPFB/vlQLAA/TtwFAA/nhFolB/TM
--------------------------------------------------------------------~->
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/