I have this program that needs to do some comparisons of strings in an array. The first thought one would have is of course to just use strcmp
to check whether two strings in the array are the same. Now consider the option that you just need to compare the pointers to the strings. This would involve some preparations to map each element that are literally the same to the same place in memory.
I've done all this, by preparing with strcmp
, and now with strstr
(which I believe is faster).
But because I need to check every string to map them to their first occurences, I get horribly long preparation-times. I should mention that this array is several MB large.
Here is an example of what I want to do:
[0x0: "I", 0x1: "am", 0x2: "done", 0x3: "here.", 0x4: "I", 0x5: "have", 0x6: "done", 0x7: "everything!"]
[0x10: 0x0, 0x11: 0x1, 0x12: 0x2, 0x13: 0x3, »0x14: 0x0«, 0x15: 0x5, »0x16: 0x2«, 0x17: 0x07]
So now to the question: Is there another way to do this kind of mapping faster than I am already doing?