Compare commits
6 commits
Author | SHA1 | Date | |
---|---|---|---|
ce7400a298 | |||
a58034aa0b | |||
5484da169c | |||
6f59393e0b | |||
7bdeb049d4 | |||
f6f9803439 |
5 changed files with 77 additions and 15 deletions
|
@ -1,7 +1,7 @@
|
||||||
cmake_minimum_required(VERSION 3.7)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
project(SimpleArchiver C)
|
project(SimpleArchiver C)
|
||||||
|
|
||||||
set(SimpleArchiver_VERSION 1.0)
|
set(SimpleArchiver_VERSION 1.7)
|
||||||
|
|
||||||
set(SimpleArchiver_SOURCES
|
set(SimpleArchiver_SOURCES
|
||||||
src/main.c
|
src/main.c
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
|
|
||||||
## Upcoming Changes
|
## Upcoming Changes
|
||||||
|
|
||||||
|
## Version 1.7
|
||||||
|
|
||||||
|
Refactor the internal hash-map data structure.
|
||||||
|
|
||||||
|
Minor update to CMakeLists.txt.
|
||||||
|
|
||||||
## Version 1.6
|
## Version 1.6
|
||||||
|
|
||||||
Enforce "safe-links" on extraction by ensuring every extracted symlink actually
|
Enforce "safe-links" on extraction by ensuring every extracted symlink actually
|
||||||
|
|
|
@ -40,6 +40,11 @@ API calls.
|
||||||
Note that `--compressor` and `--decompressor` cmds must accept data from stdin
|
Note that `--compressor` and `--decompressor` cmds must accept data from stdin
|
||||||
and return processed data to stdout.
|
and return processed data to stdout.
|
||||||
|
|
||||||
|
## Using the Cosmopolitan-Compiled Version
|
||||||
|
|
||||||
|
Note that on Linux, the `actually_portable_simplearchiver` binaries may attempt
|
||||||
|
to open via Wine (if Wine is installed). [A workaround is mentioned here.](https://github.com/jart/cosmopolitan/blob/master/README.md#linux)
|
||||||
|
|
||||||
## Changes
|
## Changes
|
||||||
|
|
||||||
See the [Changelog](https://git.seodisparate.com/stephenseo/SimpleArchiver/src/branch/main/Changelog.md).
|
See the [Changelog](https://git.seodisparate.com/stephenseo/SimpleArchiver/src/branch/main/Changelog.md).
|
||||||
|
|
|
@ -76,19 +76,17 @@ int simple_archiver_hash_map_internal_pick_in_list(void *data, void *ud) {
|
||||||
|
|
||||||
uint64_t simple_archiver_hash_default_fn(const void *key, size_t key_size) {
|
uint64_t simple_archiver_hash_default_fn(const void *key, size_t key_size) {
|
||||||
uint64_t seed = 0;
|
uint64_t seed = 0;
|
||||||
uint64_t temp = 0;
|
uint64_t temp;
|
||||||
size_t count = 0;
|
|
||||||
for (size_t idx = 0; idx < key_size; ++idx) {
|
for (size_t idx = 0; idx < key_size; ++idx) {
|
||||||
temp |= ((uint64_t) * ((uint8_t *)key + idx)) << (8 * count);
|
temp = (uint64_t)(((uint8_t*)key)[idx]) + seed;
|
||||||
++count;
|
if (idx % 3 == 0) {
|
||||||
if (count >= 8) {
|
temp ^= 0xA5A538A5A9B5A5A5;
|
||||||
count = 0;
|
} else if (idx % 3 == 1) {
|
||||||
seed += temp;
|
temp ^= 0xD7A58BD7A58BD7AA;
|
||||||
temp = 0;
|
} else {
|
||||||
|
temp ^= 0x8B7A8B8B87CB8B84;
|
||||||
}
|
}
|
||||||
}
|
seed += simple_archiver_algo_lcg_defaults(temp);
|
||||||
if (temp != 0) {
|
|
||||||
seed += temp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return simple_archiver_algo_lcg_defaults(seed);
|
return simple_archiver_algo_lcg_defaults(seed);
|
||||||
|
@ -106,7 +104,7 @@ int simple_archiver_hash_map_internal_rehash(SDArchiverHashMap *hash_map) {
|
||||||
}
|
}
|
||||||
SDArchiverHashMap new_hash_map;
|
SDArchiverHashMap new_hash_map;
|
||||||
new_hash_map.hash_fn = hash_map->hash_fn;
|
new_hash_map.hash_fn = hash_map->hash_fn;
|
||||||
new_hash_map.buckets_size = hash_map->buckets_size * 2;
|
new_hash_map.buckets_size = (hash_map->buckets_size - 1) * 2 + 1;
|
||||||
// Pointers have the same size (at least on the same machine), so
|
// Pointers have the same size (at least on the same machine), so
|
||||||
// sizeof(void*) should be ok.
|
// sizeof(void*) should be ok.
|
||||||
new_hash_map.buckets = malloc(sizeof(void *) * new_hash_map.buckets_size);
|
new_hash_map.buckets = malloc(sizeof(void *) * new_hash_map.buckets_size);
|
||||||
|
@ -154,7 +152,7 @@ SDArchiverHashMap *simple_archiver_hash_map_init_custom_hasher(
|
||||||
uint64_t (*hash_fn)(const void *, size_t)) {
|
uint64_t (*hash_fn)(const void *, size_t)) {
|
||||||
SDArchiverHashMap *hash_map = malloc(sizeof(SDArchiverHashMap));
|
SDArchiverHashMap *hash_map = malloc(sizeof(SDArchiverHashMap));
|
||||||
hash_map->hash_fn = hash_fn;
|
hash_map->hash_fn = hash_fn;
|
||||||
hash_map->buckets_size = SC_SA_DS_HASH_MAP_START_BUCKET_SIZE;
|
hash_map->buckets_size = SC_SA_DS_HASH_MAP_START_BUCKET_SIZE + 1;
|
||||||
// Pointers have the same size (at least on the same machine), so
|
// Pointers have the same size (at least on the same machine), so
|
||||||
// sizeof(void*) should be ok.
|
// sizeof(void*) should be ok.
|
||||||
hash_map->buckets = malloc(sizeof(void *) * hash_map->buckets_size);
|
hash_map->buckets = malloc(sizeof(void *) * hash_map->buckets_size);
|
||||||
|
|
|
@ -219,6 +219,59 @@ int main(void) {
|
||||||
simple_archiver_hash_map_free(&hash_map);
|
simple_archiver_hash_map_free(&hash_map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test hashing.
|
||||||
|
//{
|
||||||
|
// printf("Distribution of 13 over 33...\n");
|
||||||
|
// unsigned int counts[33];
|
||||||
|
// memset(counts, 0, sizeof(unsigned int) * 33);
|
||||||
|
|
||||||
|
// uint64_t hash;
|
||||||
|
|
||||||
|
// hash = simple_archiver_hash_default_fn("/", 2);
|
||||||
|
// printf("%s in bucket %lu (%lu)\n", "/", hash % 33, hash);
|
||||||
|
// counts[hash % 33] += 1;
|
||||||
|
// hash = simple_archiver_hash_default_fn("/faq", 5);
|
||||||
|
// printf("%s in bucket %lu (%lu)\n", "/faq", hash % 33, hash);
|
||||||
|
// counts[hash % 33] += 1;
|
||||||
|
// hash = simple_archiver_hash_default_fn("/FAQ", 5);
|
||||||
|
// printf("%s in bucket %lu (%lu)\n", "/FAQ", hash % 33, hash);
|
||||||
|
// counts[hash % 33] += 1;
|
||||||
|
// hash = simple_archiver_hash_default_fn("/url", 5);
|
||||||
|
// printf("%s in bucket %lu (%lu)\n", "/url", hash % 33, hash);
|
||||||
|
// counts[hash % 33] += 1;
|
||||||
|
// hash = simple_archiver_hash_default_fn("/home", 6);
|
||||||
|
// printf("%s in bucket %lu (%lu)\n", "/home", hash % 33, hash);
|
||||||
|
// counts[hash % 33] += 1;
|
||||||
|
// hash = simple_archiver_hash_default_fn("/blog", 6);
|
||||||
|
// printf("%s in bucket %lu (%lu)\n", "/blog", hash % 33, hash);
|
||||||
|
// counts[hash % 33] += 1;
|
||||||
|
// hash = simple_archiver_hash_default_fn("/test", 6);
|
||||||
|
// printf("%s in bucket %lu (%lu)\n", "/test", hash % 33, hash);
|
||||||
|
// counts[hash % 33] += 1;
|
||||||
|
// hash = simple_archiver_hash_default_fn("/menu", 6);
|
||||||
|
// printf("%s in bucket %lu (%lu)\n", "/menu", hash % 33, hash);
|
||||||
|
// counts[hash % 33] += 1;
|
||||||
|
// hash = simple_archiver_hash_default_fn("/posts", 7);
|
||||||
|
// printf("%s in bucket %lu (%lu)\n", "/posts", hash % 33, hash);
|
||||||
|
// counts[hash % 33] += 1;
|
||||||
|
// hash = simple_archiver_hash_default_fn("/about", 7);
|
||||||
|
// printf("%s in bucket %lu (%lu)\n", "/about", hash % 33, hash);
|
||||||
|
// counts[hash % 33] += 1;
|
||||||
|
// hash = simple_archiver_hash_default_fn("/media", 7);
|
||||||
|
// printf("%s in bucket %lu (%lu)\n", "/media", hash % 33, hash);
|
||||||
|
// counts[hash % 33] += 1;
|
||||||
|
// hash = simple_archiver_hash_default_fn("/social", 8);
|
||||||
|
// printf("%s in bucket %lu (%lu)\n", "/social", hash % 33, hash);
|
||||||
|
// counts[hash % 33] += 1;
|
||||||
|
// hash = simple_archiver_hash_default_fn("/projects", 10);
|
||||||
|
// printf("%s in bucket %lu (%lu)\n", "/projects", hash % 33, hash);
|
||||||
|
// counts[hash % 33] += 1;
|
||||||
|
|
||||||
|
// for (unsigned int idx = 0; idx < 33; ++idx) {
|
||||||
|
// printf("Bucket %u: %u\n", idx, counts[idx]);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
// Test PriorityHeap.
|
// Test PriorityHeap.
|
||||||
{
|
{
|
||||||
SDArchiverPHeap *priority_heap = simple_archiver_priority_heap_init();
|
SDArchiverPHeap *priority_heap = simple_archiver_priority_heap_init();
|
||||||
|
|
Loading…
Reference in a new issue