Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Methods 'save' of automaton and 'load' of module allow to save and load automaton in file. Save has almost no memory footprint, load does have. This mechanism is complementary to pickling. Pickling suffers from high memory consumption, the save/load pair tries to overcome this limitation.
- Loading branch information
1 parent
b28b362
commit 7f405d1
Showing
27 changed files
with
1,143 additions
and
36 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "src/custompickle/custompickle.c" | ||
#include "src/custompickle/pyhelpers.c" | ||
#include "src/custompickle/save/savebuffer.c" | ||
#include "src/custompickle/save/automaton_save.c" | ||
#include "src/custompickle/load/loadbuffer.c" | ||
#include "src/custompickle/load/module_automaton_load.c" |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "custompickle.h" | ||
#include "../../Automaton.h" | ||
|
||
|
||
static const char CUSTOMPICKLE_MAGICK[16] = { | ||
'p', 'y', 'a', 'h', 'o', 'c', 'o', 'r', 'a', 's', 'i', 'c', 'k', // signature | ||
'0', '0', '1' // format version | ||
}; | ||
|
||
|
||
void custompickle_initialize_header(CustompickleHeader* header, Automaton* automaton) { | ||
|
||
ASSERT(header != NULL); | ||
ASSERT(automaton != NULL); | ||
|
||
memcpy(header->magick, CUSTOMPICKLE_MAGICK, sizeof(CUSTOMPICKLE_MAGICK)); | ||
header->data.kind = automaton->kind; | ||
header->data.store = automaton->store; | ||
header->data.key_type = automaton->key_type; | ||
header->data.words_count = automaton->count; | ||
header->data.longest_word = automaton->longest_word; | ||
} | ||
|
||
|
||
void custompickle_initialize_footer(CustompickleFooter* footer, size_t nodes_count) { | ||
|
||
ASSERT(footer != NULL); | ||
|
||
memcpy(footer->magick, CUSTOMPICKLE_MAGICK, sizeof(CUSTOMPICKLE_MAGICK)); | ||
footer->nodes_count = nodes_count; | ||
} | ||
|
||
int custompickle_validate_header(CustompickleHeader* header) { | ||
if (memcmp(header->magick, CUSTOMPICKLE_MAGICK, sizeof(CUSTOMPICKLE_MAGICK)) != 0) | ||
return false; | ||
|
||
if (!check_store(header->data.store)) | ||
return false; | ||
|
||
if (!check_kind(header->data.kind)) | ||
return false; | ||
|
||
if (!check_key_type(header->data.key_type)) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
|
||
int custompickle_validate_footer(CustompickleFooter* footer) { | ||
return (memcmp(footer->magick, CUSTOMPICKLE_MAGICK, sizeof(CUSTOMPICKLE_MAGICK)) == 0); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include "../../Automaton.h" | ||
|
||
typedef struct AutomatonData { | ||
AutomatonKind kind; | ||
KeysStore store; | ||
KeyType key_type; | ||
size_t words_count; | ||
int longest_word; | ||
} AutomatonData; | ||
|
||
|
||
typedef struct CustompickleHeader { | ||
char magick[16]; // CUSTOMPICKLE_MAGICK | ||
AutomatonData data; | ||
} CustompickleHeader; | ||
|
||
|
||
typedef struct CustompickleFooter { | ||
size_t nodes_count; | ||
char magick[16]; // CUSTOMPICKLE_MAGICK | ||
} CustompickleFooter; | ||
|
||
|
||
void custompickle_initialize_header(CustompickleHeader* header, Automaton* automaton); | ||
void custompickle_initialize_footer(CustompickleFooter* footer, size_t nodescount); | ||
int custompickle_validate_header(CustompickleHeader* header); | ||
int custompickle_validate_footer(CustompickleFooter* footer); |
Oops, something went wrong.