Re: Mutually exclusive item filtering-comparing
Re: Mutually exclusive item filtering-comparing
- Subject: Re: Mutually exclusive item filtering-comparing
- From: Joseph Dixon <email@hidden>
- Date: Tue, 05 Nov 2013 12:38:30 -0600
Let’s assume the data source sorts items with one handed weapons at the top of the list and two handed weapons at the bottom. Also assume the data source knows the row index of the first two handed weapon. Now we can test for one or two handed weapons by comparing the row index to that of the first two handed weapon. If a user selects a one handed weapon in the left hand, then change tableView:numberOfRowsInSection: for the right hand table to show only one handed weapons. If the user has chosen a two handed weapon in the left hand, then change tableView:numberOfRowsInSecton: for the right hand table to show zero. This can be done without any looping at all.
Does this help?
-jwd
// Joseph W. Dixon
On Nov 5, 2013, at 12:17 PM, Chris Paveglio <email@hidden> wrote:
> What is the most efficient way to compare a list of mutually exclusive items? I know this isn't exactly Cocoa/iOS specific. I have a table that needs to disable certain rows based on what other rows are selected.
>
> I have several objects, let's say "weapons in a game". Such as a bow and arrow, a rifle, a bazooka.
> A character can use any of the objects, but some can't be used together. A bazooka is too big and requires 2 hands to carry so you can't select both a bazooka and rifle at the same time. You can select bow & arrow and rifle, but if you select both of those, you can't take the bazooka too. I hope you get the idea.
>
> My exclusions array has many simple objects. Each object has 3 ivars- (int)itemID1, (int)itemID2, (string)isMutuallyExclusive (not my design but could be changed if there is a better way).
>
> The idea I have is whenever a row is selected, I will take the itemID of that item, then iterate with every other itemID in the table- then I do an iteration on every object in the exclusions array. If the selected row itemID is in the exclusion object, and current row itemID being compared are both in the exclusion object, I can get it's exclusion (non-exclusive items won't be in the list).
> So, repeat with 100 items in the table, each table row comparing against the exclusion list which has over 100 entries. It could result in up to 10,000 comparisons getting tested until the exclusion is found or exhausted.
>
> It seems extremely process intensive. Is there a better way, or some basic concept I might be missing?
>
> Thanks,
> Chris
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden