vincenzopalazzo / cpstl

Copy and Paste standard library (CPSTL) is a repository with a collection of data structure and algorithms in many different languages
https://docs.page/vincenzopalazzo/cpstl
GNU General Public License v2.0
14 stars 3 forks source link

cpp: rolling hash need to take the reference of the string not the copy #35

Closed vincenzopalazzo closed 2 years ago

vincenzopalazzo commented 2 years ago

We have the following code in https://github.com/vincenzopalazzo/cpstl/tree/master/cpp/algoritmins/karp_rabin_fingerprint

  T hash(std::string value) {
    auto vector_bytes = string_to_to_bytes(value);
    // x' = ((x « 1) + bit[i]) % p
    for (std::size_t i = 1; i < vector_bytes.size(); i++) {
      vector_bytes[i] = (vector_bytes[i - 1] + vector_bytes[i]) % prime_number;
    }
    return vector_bytes.back();
  }

We just need the reference of the string, so some things like that

  T hash(std::string const &value) {
    auto vector_bytes = string_to_to_bytes(value);
    // x' = ((x « 1) + bit[i]) % p
    for (std::size_t i = 1; i < vector_bytes.size(); i++) {
      vector_bytes[i] = (vector_bytes[i - 1] + vector_bytes[i]) % prime_number;
    }
    return vector_bytes.back();
  }
Mouradouchane commented 2 years ago

hi man , i think i can do that 😄

vincenzopalazzo commented 2 years ago

Hi @Mouradouchane,

Ops I just fixed this, because I found a bug in my implementation. Do you want to take any other task? What do you like to do on this repository? I can help you to start if you want

Mouradouchane commented 2 years ago

thanks @vincenzopalazzo , i am currently ,"studying and training" on data-structures using C++ i think , i can help in that topic

vincenzopalazzo commented 2 years ago

@Mouradouchane It is amazing, I will be happy to review your PR, and maybe discuss what we need to support from a data structure point of view, by open a new discussion :)

Mouradouchane commented 2 years ago

currently i am working on dynamic_tree , you can take a look on it https://github.com/Mouradouchane/data_structures/blob/main/data_structures/trees/dynamic_tree.hpp

if you want , we can add it here in that repo and improve it .

vincenzopalazzo commented 2 years ago

if you want , we can add it here in that repo and improve it .

Of curse, I would love someone that help me to improve this repository. I have only one rule, I love to use the C++ guideline in the repository. So, we need to change a little bit style of the code but I think it is not a big deal, right?

Mouradouchane commented 2 years ago

yeah sure no problem 😄

Mouradouchane commented 2 years ago

hi , man you have any social media account telegram or instagram or ... 😀

vincenzopalazzo commented 2 years ago

hi , man you have any social media account telegram or instagram or ... grinning All listed here https://github.com/vincenzopalazzo

BTW, there is also discord with vincenzopalazzo nickname

Mouradouchane commented 2 years ago

discord name missing #numbers 😄 => vincenzopalazzo#xxxx

vincenzopalazzo commented 2 years ago

discord name missing #numbers smile => vincenzopalazzo#xxxx

Ops! Sorry vincenzopalazzo#3884