Gmatch Not Working, Query Array For Duplicates And Select Duplicates

i have more to this script but i cannot get this part working. Im basically trying to find duplicate index values in an array and select them. I'm pretty sure im going about this the wrong way, so any help is appreciated.

BUDLoNG

CODE
proc findDuplicateShit()
{

string $duplicateMeshes;
int $finalArray[] = {243386223,243386223,353769540,5838373,353769540};
int $size = size($finalArray);

    for ($z =0; $z<$size; $z++)
    {
$duplicateMeshes = $finalArray[$z];

        print "\n";
        print "\n";
        print "\n";
        print "\n";

        if (gmatch $finalArray "$duplicateMeshes")
        {
            print "MATCH";
            print $finalArray[$z];
            print "\n";
            print "\n";
        }
        else
        {
            print "no matches you silly fool";
            print "\n";
        }    

}    
}

findDuplicateShit;

Your code does not do anything. Not to mention:

if (gmatch $finalArray "$duplicateMeshes")

Wich really does not make ANY sense whatsoever. (gramtch works on strinngs $final array is a int array and "$duplicateMeshes" is always the string $duplicateMeshes, nevera assigned value)

Anyway is the order of the array sensitive? because that makes a O(n) algoritrhm instead of a nearly O(n^2) one

i am pretty lost on what to do.. i am not an expert at this, and mabye not even intermediate, but i am trying to learn.

the purpose of the code is to find a duplicate value in an array and return it.

is gmatch the correct way to go about this, and i just used it incorrectly, or is there a better way not using gmatch?

thanks for your time

BUDLoNG

sort the array, and compare each value to the next. then you get all values with duplicates. Otherwise you need to chek each value to each other value.

thats the thing, i dont want to sort, i am using the index # to reference objects in the scene in other parts of my code.

is it possible to find the dups without sorting?

Yes, but its WAY cheaper to sort and test.

see if you have 100 entries in your list sorting then testing is a loop of 100 whereas testing in place is a 5050 operations job, wich means that its also 50 times faster excluding time it takes to sort (wich is fast since its a c++ kernel), now if you have 5000 entries the sorted list is 5000 and the nonsorted 12million times more computation time.

So for this sheer difference its best to find out the duplicates first and THEN find their indexes.

thanks.. ill keep working on it, and post back if i have issues.

thanks for the help

BUDLoNG

im am pretty close to completion..i think.. but i cannot seem to get this to work properly. $finalIndex keeps returning extra values ----"0" 's...

[codebox]///the puropse of this tool is to find duplicate geometery in a scene based on bounding boxes, not naming convention
///this tool should create bounding boxes around all meshes in the scene
///if two or more bounding boxes are at the exact same location, select those meshes

global proc int getArrayIndexOf(string $thisString, string $inThisArray[])
{
int $numItems = size($inThisArray);
for ($i = 0; $i < $numItems;$i++)
{
if ($inThisArray[$i] == $thisString)
return $i;
}
return -1;

	}

proc gbRest()
{
string $sceneList[] = ls -g;
int $sceneListSize = size($sceneList);

float $boundBox[];
float $dataDotsum[];
int $compareMe;
string $finalArray[];
//////loop thru array creating bounding box info///
for ($i =0; $i<$sceneListSize; $i++)
	{
	$boundBox = `polyEvaluate -b $sceneList[$i]`;

	//////feedback////////
	print $sceneList[$i];
	print "\n";
	print $boundBox[0];
	print "\n";
	print $boundBox[1];
	print "\n";
	print $boundBox[2];
	print "\n";
	print $boundBox[3];
	print "\n";
	print $boundBox[4];
	print "\n";
	print $boundBox[5];
	print "\n";


	////////multiple to new array for comparison//////
	$dataDotsum={$boundBox[0] * $boundBox[1] * $boundBox[2] * $boundBox[3] * $boundBox[4] * $boundBox[5]};
	print $dataDotsum;
	print "\n";
	print "\n";
	////////loop thru boundbox sum array copying to new array//////
		for ($dotSum in $dataDotsum) 
			{ 
		$compareMe = $dotSum;
			}
		$finalArray[$i] = $compareMe;
	//////feedbackTESTING////////
	print "\n";
	print "\n";

	}

////copy finalArray to finalArraysort and sort////
string $duplicateMeshes;
string $finalArraysort[];
print "$finalArray";
print "\n";
print $finalArray;
string $finalArraypresort[] = stringArrayRemoveDuplicates($finalArray);
$finalArraysort = sort $finalArraypresort;
print "$finalArraypresort";
print "\n";
print $finalArraypresort;
int $finalArraySize = size($finalArray);
for ($z =0; $z<$finalArraySize; $z++)
{
$duplicateMeshes = $finalArraysort[$z];

}
///loop thru $finalArraysort anytime a duplicate value is hit, copy that value to a new array $lightMeup[] ---THIS IS ADDING AN EXTRA VALUE??
string $lightMeup[];

for ($z =0; $z<$finalArraySize; $z++)
{

if ( $finalArraysort[$z] == $finalArraysort[$z++])

	{
		///
		$lightMeup[$z] = $finalArraysort[$z];
		///
	}
	else 
	{
		print "your scene is >>>C L E A N<<<";
		print "\n";

	}

}
///test print////
///test print////
///test print////
///test print////
print "$finalArraysort";
print "\n";
print $finalArraysort;
print "\n";
print "$lightMeup";
print "\n";
print $lightMeup;
print "\n";
print "$finalArray";
print "\n";
print $finalArray;
print "\n";

///////select $lightMeup array values inside of $finalArray to locate index numbers

int $finalIndex[];
int $lightMeupSize = size($lightMeup);

for ($z =0; $z<$lightMeupSize; $z++)
{

int $indexComp = getArrayIndexOf $finalArray[$z] $lightMeup;
if ($indexComp != -1)
{
$finalIndex[$z] = $indexComp;

}

}
/////string $finalIndexremDup[] = stringArrayRemoveDuplicates($finalIndex);
/////////loop thru final index to select objects//////STUCK---FUCKSHIT
string $finalMeshes[];
int $m;
int $finalIndexSize = size($finalIndex);

for ($x =0; $x<$finalIndexSize; $x++)
{
	 $m = $finalIndex[$x];
	select $sceneList[$m];
	$finalMeshes[$x]=$sceneList[$m];
}

print "\n";
print "$finalIndex";
print "\n";
print $finalIndex;

select $finalMeshes;
print "$finalMeshes";
print "\n";
print $finalMeshes;

////CLEAR ALL ARRAYS to free up memory////
clear $finalArray;
clear $finalArraysort;
clear $lightMeup;
clear $boundBox;
clear $dataDotsum;
clear $sceneList;
clear $finalIndex;
clear $finalMeshes;

}

gbRest;

[/codebox]