Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting OUs

Status
Not open for further replies.

PScottC

MIS
Mar 16, 2003
1,285
US
I currently have a script that pulls a list of OUs into an ADODB RecordSet. In the query I pull the DN and canonicalName of the OU. I then take the canonicalName of the OU and sort the list using a bubble sort function.

I've got approximately 180 OUs and I've found that this process isn't very efficient, especially since bubble sorts don't scale well beyond about 100 elements.

What I'm looking for is a way to sort the results directly in ADODB. Unfortunately, the canonicalName attribute is returned from AD as a multi-value string, and this type of data cannot be sorted using the oRecordSet.Sort property.

Is there a way of sorting data from the right instead of from the left? Then I can use the DN field to sort on.

The reason that I'm using canonicalName is because it is easy to read...

i.e.
domian.tld
domian.tld/RootOU
domian.tld/RootOU/ParentOU
domian.tld/RootOU/ParentOU/SubOU

Ideas?

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Surely, even a bubble sort cant take more than a couple of milliseconds to sort only a couple hundred items??

Why can you not simply sort by DN?

Sort by Name?

Use quicksort?

 
Well... DNs look like this:

OU=MySub1,OU=RootOU1,DC=domain,DC=tld
OU=RootOU1,DC=domain,DC=tld
OU=MySub2,OU=RootOU1,DC=domain,DC=tld

How do I sort the DNs so that RootOU1 comes before MySub1? I would have to either rearrange the elements of the DN (time wasting) so that I could sort them using a normal method that reads from right to left, or ??? Here's where my question is... Is there a sort method that reads from the other end of the string?

Repeated runs of the script have been a bit sluggish and I'm looking for a way to make it more efficient.

I am looking at quicksort, I'm just annoyed that I have to extract all the data from my ADODB object and put it into an array (time wasting) just to get the data sorted the way I need it.

Let me know if I should stick with quicksort, or if you think of another way.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
OK, yes, silly me.

I doubt the sorting is the slow bit. I'd add some Wscript.Echo Now
prexied logging in your script so you can see which parts are taking the time.

Bubble sort is slow... performance at N^2 magnitude
Quicksort is N Log 2 N

For 180 records, bubble sort would take avg effort 32400
and quicksort would take effort 1350 (4% of the time)

Real gains would be found during large record sets. Take 1 million records and perform the above calculations and quicksort would take 0.002% of the time of bubble sort (which is why bubble sort is not used)

However, the VBScript overhead will probably minimise any gain.... i dunno... can you try it?


 
Good find... He simply copies the data from oRecordSetA to oRecordSetB, then sorts B.

I thought about doing that, but wasn't sure of the performance implications of having multiple recordsets open at the same time.



PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top