mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-08-21 10:42:07 +00:00
update
This commit is contained in:
parent
3204ce5c1e
commit
f41c1341a0
36
src/8/20/hash.cpp
Normal file
36
src/8/20/hash.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <ios>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
using ull = uint64_t;
|
||||
|
||||
template<ull P=47,ull maxsize=(ull)1e3>
|
||||
struct Hash{
|
||||
ull hash{};
|
||||
std::vector<ull> powp;
|
||||
Hash(const std::string&s):powp(maxsize){
|
||||
ull npp=P;
|
||||
powp[0]=1;
|
||||
powp[1]=npp;
|
||||
for(ull i=2;i<maxsize;i++){
|
||||
npp*=npp;
|
||||
powp[i]=npp;
|
||||
}
|
||||
ull k=0;
|
||||
for(auto it=s.rbegin();it!=s.rend();++it){
|
||||
hash+=((*it)-'A'+1)*powp[k];
|
||||
}
|
||||
}
|
||||
bool operator==(const Hash<P,maxsize>&o)const{
|
||||
return hash==o.hash;
|
||||
}
|
||||
};
|
||||
|
||||
#define pv(v)do{std::cout<<std::boolalpha<<#v<<" :"<<(v)<<'\n';}while(0)
|
||||
|
||||
int main(){
|
||||
pv(Hash("aaaaaaaa")==Hash("aaaaaaa"));
|
||||
}
|
Loading…
Reference in New Issue
Block a user