CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    85

    Need "File Compare Algorithm" help

    I'm racking my brain trying to think of a simple yet efficient way to do the following... I have two files to compare, a C file and a T file. The C file is an ASCII file and the T file is a binary file. Both contain "n" amount of "System" elements and each system can contain "n" "Node" elements, kind of like a tree structure. The C file is handed to me and is used as the basis for constructing a T file. A System & a Node can only be added to a T file if it's in the C file and can only be deleted from a T file if it's no longer in the C file. With me so far? So I need to compare these two files and I'm trying to figure out how. Here's what I have so far...

    1) Read in the C file, store the Systems & Nodes in a vector and do the same for the T file. Compare the vectors and make additions & deletions based on this... seems like the additons & deletions wil be LOTS of overhead...

    2) Write a bool function to search for Systems & Nodes in a T file based on what's in the C file. Make additions & deletions based on this...

    3) Parse the T file and for every System & Node I find, parse the C file to see if it exists...almost like in #2 above but use the T file to search in the C file...

    None of these seem like a "great" idea but I've never compared two files so I'm trying to not make more work for myself nor screw it up! Any ideas....?

    Thanks for reading my post...!

  2. #2
    Join Date
    Mar 2001
    Posts
    2,529
    why not create a node class.

    for each node and read in all the elements from both files.

    then overload the = operator and run some comparison algorithms from any college textbook as if you were comparing 2 arrays of integers.

    This way you could apply alot of common algorithms to your problem.

    ahoodin

  3. #3
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    85
    Originally posted by ahoodin
    why not create a node class.

    for each node and read in all the elements from both files.

    then overload the = operator and run some comparison algorithms from any college textbook as if you were comparing 2 arrays of integers.

    This way you could apply alot of common algorithms to your problem.

    ahoodin
    That's kinda lke I was thinking about in the #1 scenario in my first post...except I'd have a vector of System structs that are built when the files are read in.... The only problem I found with that so far is say, System #22 exists in both C & T files BUT in the C file it had 10 Nodes and in the T file it has 9 Nodes... I'll have to add just a Node to an existing System in the T file and I'll have the added overhead of finding it int he T file because all I have are vectors full of System and Nodes "copies" and not the actual object....
    Last edited by Thresher; August 28th, 2003 at 10:03 AM.

  4. #4
    Join Date
    Feb 2002
    Posts
    5,757
    One solution is is recursion. Read both files in binary mode. The C file will be the key. THe dispatch function first determines the attribute of the C file and dispatches it to either the system element check or node check. Work from there.

    Kuphryn

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured