4 ms·
I am not a comp science guy, and I just know next to nothing in case of either data structures and algorithms. But, knowing how and why the data structures work
by rottc0dd 6y ago
I am not a comp science guy, and I just know next to nothing in case of either data structures and algorithms. But, knowing how and why the data structures work can help you when slapping the code does not work.
We had a code base maintained for almost 5 years that has to deal with one type of representation of data to another. The result form allows keeping combining two data points with some differences i.e. calls and arguments.
The combining the nodes and finding the differences happens as last step. It was just too much hassle to deal with comparison because, the initial form does not have much complexities but resultant form has much more complex datatypes. And we have to compare it with all potential things that could match. The complexity is inherent to the problem of comparing final representation.
Maybe it is obvious to other people here, but when I saw how the hashmap works, I was blown away. It is not just about having any datatype as index, it is about how efficiently you can find the index. It was about REDUCING THE EQUALITY CHECK. Because, it is costly, particularly when you are dealing with very deep tree nodes. That is where hash comes in.
So, we traversed the nodes once and created a signature of the structure that cannot be made into arguments and some other metadata determining its type i.e. hash. And we introduced an intermediate representation for effective comparison that is hybrid of initial and final representation. That sped things up so much. Now almost all the work of five years has to be thrown away.
I think such things exist in almost all projects. You would not know you need it, until you need it.
Edit: Added a point.