Jump to content

How do I delete redundant elements?

Recommended Posts

You would need to read through the file to develop an array of unique strings and then write the array back to that file. Here's some pseudo-code:

open the file

while (there's another line to read)
    read the line
    search the array for that line
    if (the array doesn't contain that line)
        add it

delete original file
write array to that location
; (there's most probably a UDF for this
; or maybe AutoIt natively supports it via its FileXXX() commands

This shouldn't be too hard to code. Let us know if you get stuck!

Link to comment
Share on other sites

Like the others (Burrup, LxP) said, you need to read each line in to an array, then check for it's existence before writing it out to an output file.

But instead of using a flat array (that would get slower the bigger the file gets) I'd recomend you use my binary tree algorythm to store the strings:


Link to comment
Share on other sites

Thanks blindwig - that's what I was looking for. I knew I could just use a normal array, but I'm working with thousands of entries. I had read somewhere that binary trees are faster for sorting. Now I just need to figure out how to implement it...

Link to comment
Share on other sites

Well, if you end up using my BTree UDF, you'd do it something like this:

$btLines = _BTreeCreate()
;loop through the file
_BTreeSet($btLines, FileReadLine())

;Then treat the tree like a 1-based 2-d array (which it is):
;loop 1 to $btLines

The only issue is that currently my binary tree routine is not case-sensative.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...