-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from WojciechMula/custom-save-load
Custom save load
- Loading branch information
Showing
29 changed files
with
1,282 additions
and
38 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
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
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.