Skip to content

Conversation

@zhaolu996
Copy link

@zhaolu996 zhaolu996 commented Jul 5, 2021

Hi! I have refined two functions : IsNIdIn(const TInt&) and AddVMerged(TVec&).

The value member NIdV of the class TCnCom is unsorted, so the original IsNIdIn(const TInt&) worked incorrectly. I fixed it simply by replacing the binary search with the forwarding search. I add a few lines of test codes to show the incorrectness/correctness of the original/refined implementation.

Another issue I discovered when using snap is that the AddVMerged(TVec&) was slower than I expected. And my contributions to this issue are :

  • The original codes are simple, clear, and robust. However, its complexity is O(xy), where x is this->Len() and y is the length of ValV. I reimplemented this function with complexity approximately O(ylgy+x). The old implementation would move the elements backward multiply times. The new implementation moves these elements just once because it moves the elements at the end of this TVec first.

  • Since no unit test for the classes and functions in ds.h, I put my unit tests for the new implement of this function at: https://github.com/DaosWelcome/snap/blob/dev/test/test-TVec.cpp. And the new implementation passed the tests.

  • A simple efficiency comparison experiment is also provided at https://github.com/DaosWelcome/snap/blob/dev/test/test-TVec.cpp. On my mac laptop, the new implementation is around 50 times faster.

I would hope these two simple refinements would be helpful.

Zhao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant