Jump to content
  • Advertisement
Sign in to follow this  

Comparing & Finding changes

This topic is 4346 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, on paper my problem is easy to fix, but in reality i have only little idea about how to do this. So this is what i have
string olddata = "100,354,999,123,555";
string newdata = "100,200,123,234";
any ideas about how to find out which values are deleted and which are added? i expect to see something like this as result:
string added = "200,234";
string removed = "354,999,555";
Any help would be appreciated :) p.s. im using c#

Share this post


Link to post
Share on other sites
Advertisement
I don't know c#, but I imagine the general procedure would be:

1)Convert the old and new lists of numbers from one long string into tokens. There are probably library functions for this.

2)Convert those tokens into integers. I'm sure there's some type of container like a vector in c#, so use that to store the tokens in.

3)Sort the containers

for your example you would have something like this right now:
oldNumbers newNumbers
100 100
123 123
354 200
555 234
999

4)Create two indices, one for each container

5)Create two new containers to store the added and removed data. You can probably just go directly from integers to strings here

6)Compare the values from above for each case:
a)if both numbers are equal, incrememnt both indices
b)if oldNumbers > newNumbers add the number from newNumbers into the 'added numbers' container. Then increment the index for newNumbers
c)if oldNumbers < newNumbers add the number from oldNumbers into the 'removed numbers' container. Then increment the index for oldNumbers
d)if one container is empty, just output the non-empty container into the appropriate add or remove container

I think that will do it. Hopefully I didn't leave out any steps.

EDIT: case D is important too!

Share this post


Link to post
Share on other sites
First, I assume that you are able to split your strings into individual strings that represent your numbers. Then the algorithm is rather simple:
olddatacpy = olddata
for each number N in newdata
if N is in olddatacpy {
remove N from olddatacpy
} else {
add N to added
}
}
removed = olddatacpy

If you need a more general diff algorithm, it will be trickier :)

HTH,

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!