Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411423 Posts in 69363 Topics- by 58416 Members - Latest Member: JamesAGreen

April 18, 2024, 07:54:29 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)As3 - finding if any elements match within a Vector
Pages: [1]
Print
Author Topic: As3 - finding if any elements match within a Vector  (Read 838 times)
pgil
Level 0
**


View Profile
« on: December 14, 2014, 07:10:23 AM »

Hey there.  I have a (hopefully) simple question.

Let's say I have a vector that contains a bunch of Points. It looks something like this:
Code:
(1,8) (3,6) (4,2) (4,5) (3,6)

In this example, you can see that the second and fifth points are identical.  I've been trying to figure out a simple way to check for duplicate elements.  Do I have to iterate through, checking each element against each other, or is there a simpler way? 
Logged
nox
Level 0
***



View Profile WWW
« Reply #1 on: December 14, 2014, 10:03:47 AM »

If you must use a vector, then you'll have to iterate through, checking each element. Two things that could make that faster though are either 1. Sorting the vector so that you don't have to iterate over EVERY element and/or 2. Checking for uniqueness on insertion.

If you can use something other than a vector, look for an implementation of the Set data structure, or another data structure that forces uniqueness, in AS3. Alternatively, you can get away with using a normal AS3 Dictionary.
Logged

pgil
Level 0
**


View Profile
« Reply #2 on: December 15, 2014, 04:48:05 PM »

Cool, thanks. It looks like just looping through the array is the simplest way to go. I'm only checking 4-5 items at most, and I'm already checking each time I add a point.

Actually, finding duplicates is just a small part of the problem I'm working on. Maybe tomorrow I'll post a more detailed explanation of what I'm trying to do.  I actually haven't completely locked down how it should work, so... I should probably... go do that...
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic