swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need help/examples with enumerated lists


From: Benedikt Stefansson
Subject: Re: Need help/examples with enumerated lists
Date: Thu, 16 Jul 1998 13:18:00 -0700

Hi Paul,


> I've got Recruiter agents that go around making offers, and when
> an offer is accepted, a Citizen agent executes a method that puts its
> name on the memberList of that Recruiter.  Each Recruiter generates
> a list of citizens to contact each time period, but that list may
> contain some of the names of the people who are already in memberList.
>
> If I want to remove from the contactList all people who are already
> in memberList, what do I do?

The easiest way to accomplish this is to use the "contains" method of
collections, which returns 1 if the member is there.

int i,member;

for(i=0;i<[contactList getCount];i++) {
    member=[contactList atOffset: i];
    if([memberList contains: member]==1)
        [contactList remove: member];
}


> Or, what if I want to make sure that all people in memberList are also
> in contactList every time, so the Recruiter touches base with new
> prospects and each of the existing members every time.

Well, you might want to think of this in terms of three seperate lists,
contact and member lists which have no members in common and now a third list
which is the union of the two. At the appropriate moment in each time step,
once you have run the previous loop and thus made sure that memberList and
contactList have no members in common do this:

[unionList removeAll];
for(i=0;i<[memberList getCount];i++)
    [unionList addLast: [memberList atOffset: i]];
for(i=0;i<[contactList getCount];i++)
    [unionList addLast: [contactList atOffset: i]];


> Each citizen has a variable "idNumber" that can be used to differentiate
> them. I just don't understand how to put it together.  The swarm examples
> in swarmapps,  did you ever notice, make no use of indexes for lists, much
> less complicated ones.

Don't use the idNumbers, it's much neater to do everything directly with the
id pointer to the object (the members) which is unique.

Hope this helps,
-Benedikt


                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]