Created
February 4, 2022 17:30
-
-
Save levonet/5a32a0892cf298aa2ae256afff8c422d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/types.h> | |
typedef uintptr_t ngx_uint_t; | |
#define ngx_tolower(c) (u_char) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c) | |
#define ngx_hash(key, c) ((ngx_uint_t) key * 31 + c) | |
/* hash-function from nginx as is */ | |
ngx_uint_t | |
ngx_hash_key_lc(u_char *data, size_t len) | |
{ | |
ngx_uint_t i, key; | |
key = 0; | |
for (i = 0; i < len; i++) { | |
key = ngx_hash(key, ngx_tolower(data[i])); | |
} | |
return key; | |
} | |
int main(int argc, char *argv[]) { | |
uint key = 0; | |
if (argc > 1) { | |
key = (uint) ngx_hash_key_lc((u_char *) argv[1], strlen(argv[1])); | |
} | |
if (argc == 2) { // Return hash key | |
printf("%u\n", key); | |
return 0; | |
} | |
if (argc == 3) { // Return remainder | |
printf("%u\n", key % atoi(argv[2])); | |
return 0; | |
} | |
printf("Error: %s should have one or two arguments.\n\n", argv[0]); | |
printf("Usage: %s <string> [divisor]\n\n", argv[0]); | |
return 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"": 0, | |
" ": 32, | |
"o": 111, | |
"o": 111, | |
"8R": 1850, | |
"RzQX": 3517039, | |
"qAdPI3Fq": 2527113169, | |
"00q8lYVWBOOugKmK": 2698177386, | |
"EtexacF7jIc2GS73JDdgeMAmUqt84BJg": 4120059431, | |
"EtexacF7jIc2GS73JDdgeMAmUqt84BJg": 4120059431, | |
"Y1ydzz9QIWpUaIK4KvavJ4I5IBE6bWlP5JzywR6CkfNwLwiDt4yj8S3x3HHn9dNB": 2873098985, | |
"WYYi8T0j4WgdnX43iFvSVGF2jjIFBJrY7TqqhKB3aovbPsuflT20FgMIETmFkaROgRf1wopLwthanGIjKDDWohe4oE4GyNSn5LyiQibUQlafyHCX07Eao3hxWkZhmunO": 698697744, | |
"mUIoM7Aj6cYtA8JiBKPqlkASX9apzhu9beXHYvtQ5N2S8GLD03B24UDn1Uqj8neKyloV72tE7esaJJv1OuuhvoWLz1a02VZnyA6frFevQ5JGjnER9czkd72lD3vL02gGA8E0lUyR08pJaly3wEsFrDJIUd0IPROOCTa2PPD5W118hMBwICIEEtiqJKBqZe6w1taUGgsXSIPHvn2BaoZ0lgMpNFF1jezdfz0flN336tEr4O4Am6TxNWtk7yI4GhIi4y8ymmVwinqhpg4D": 2016586975, | |
"0": 48, | |
"2": 50, | |
"2": 50, | |
"41": 1661, | |
"7312": 1689085, | |
"089110": 1427663167, | |
"26281363": 3406414569, | |
"7835407648": 3955229922, | |
"687504006167": 3977578720, | |
"40459490929208": 4022016297, | |
"0351006781232188": 2348588185, | |
"190135620096532713": 1781501865, | |
"1901356200965327131": 3686950312, | |
"19013562009653271311": 2626310025, | |
"3187359476680349621918278854529790319177": 4164541658, | |
"953737784211811509779320943881345589292943205013887462319416": 3753440891, | |
"50533748625943387371182828580323161439313733678329198330229997677262253695289743": 431502339, | |
"31454302632311981083034899088763577388746655861705256870440658994643773100576593885749937143160990077114828197716765516190522438228450471188232187560636686872030557541262182078314687012911564703597807906040941973299671703363754942713882026192417344257674409648534079795905": 1037621883 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment