-
Notifications
You must be signed in to change notification settings - Fork 2
/
hamm.h
24 lines (19 loc) · 1004 Bytes
/
hamm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* Fast hamming distance
Copyright (C) 2021 scrubbbbs
Contact: screubbbebs@gemeaile.com =~ s/e//g
Project: https://github.com/scrubbbbs/cbird
This file is part of cbird.
cbird is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
cbird is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with cbird; if not, see
<https://www.gnu.org/licenses/>. */
#pragma once
/// 64-bit hamming distance using special x86 instruction
inline int hamm64(uint64_t a, uint64_t b) { return __builtin_popcountll(a ^ b); } // fixme: use std::popcount() - c++20