String comparisons
Moderator: General Moderators
String comparisons
When I want to compare many strings, which is a better way of doing things - Direct Comparison using strcmp or construct a hash table and then do the comparison?
Depends on the purpose. If you don't need to hash them, then why hash them?
If you do hash them, it presents the (small) problem of some strings may evaluate to the same hash even though they are different data.
If you do hash them, it presents the (small) problem of some strings may evaluate to the same hash even though they are different data.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
The purpose is to find values that repeat themselves and set a value of one in a third column if the value is found. For example, I take the first string and compare it with the rest of the 999999 strings and wherever I find a match, I will set the corresponding third column to 1. Next, I will take the second string and then put 2 in the third column wherever i find a match. Can you advice now please?
There's no need to hash.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
So you want me to use the native string function in php to do that? Wouldn't that be slow? I mean, I will have to take the first string and compare it with the rest of the 999999 and then take the second and compare it with 999997... I see it as too many computations... Otherwise, do you suggest anything more efficient here?
Thank you. Actually that would've worked for one array but my data is distributed in rows so I need to fetch one row at a time and make a comparison I guess. To give you an example, it would look like this:
...Column A...Column B...Column C
...12..............14..............1
...32..............44..............2
...16..............15..............
...72..............12..............1
...11..............14..............1
...64..............44..............2
In the above example, Column C is initially 0 and as I traverse through the table and find corresponding similarities, I set a bit in Column C to 1,2,3...
...Column A...Column B...Column C
...12..............14..............1
...32..............44..............2
...16..............15..............
...72..............12..............1
...11..............14..............1
...64..............44..............2
In the above example, Column C is initially 0 and as I traverse through the table and find corresponding similarities, I set a bit in Column C to 1,2,3...