| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-01-29 19:54:26 +0100 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-01-29 19:54:26 +0100 |
| commit | 1373211465c34015ee900e097aa87fbffb401187 (patch) | |
| tree | 8ffa1f9296097c91627c05874fcf4559cac45de7 /src/knowledge | |
| parent | df3657b2a99ef20da99ac3c6c02f43cc23e70fca (diff) | |
Trying out ACSL, continuing implementation.
Diffstat (limited to 'src/knowledge')
| -rw-r--r-- | src/knowledge/knowledge.c | 2 | ||||
| -rw-r--r-- | src/knowledge/knowledge.h | 8 | ||||
| -rw-r--r-- | src/knowledge/knowledge_finalize.c | 6 | ||||
| -rw-r--r-- | src/knowledge/knowledge_learn_markov_sequence.c | 9 | ||||
| -rw-r--r-- | src/knowledge/knowledge_learn_sequence.c | 25 | ||||
| -rw-r--r-- | src/knowledge/knowledge_learn_word.c | 34 | ||||
| -rw-r--r-- | src/knowledge/knowledge_search.c | 13 | ||||
| -rw-r--r-- | src/knowledge/knowledge_types.h | 3 |
8 files changed, 55 insertions, 45 deletions
diff --git a/src/knowledge/knowledge.c b/src/knowledge/knowledge.c index 95683b9..463d40b 100644 --- a/src/knowledge/knowledge.c +++ b/src/knowledge/knowledge.c @@ -26,6 +26,7 @@ int ZoO_knowledge_lock_access const struct ZoO_pipe io [const restrict static 1] ) { + /* TODO */ return 0; } @@ -35,4 +36,5 @@ void ZoO_knowledge_unlock_access const struct ZoO_pipe io [const restrict static 1] ) { + /* TODO */ } diff --git a/src/knowledge/knowledge.h b/src/knowledge/knowledge.h index 872bb94..c65ee2c 100644 --- a/src/knowledge/knowledge.h +++ b/src/knowledge/knowledge.h @@ -41,7 +41,7 @@ int ZoO_knowledge_learn_word ( struct ZoO_knowledge k [const static 1], const ZoO_char word [const restrict static 1], - const ZoO_index word_length, + const size_t word_length, ZoO_index result [const restrict static 1], const struct ZoO_pipe io [const restrict static 1] ); @@ -50,7 +50,7 @@ int ZoO_knowledge_learn_sequence ( struct ZoO_knowledge k [const restrict static 1], const ZoO_index sequence [const restrict static 1], - const ZoO_index sequence_length, + const size_t sequence_length, const ZoO_index markov_order, const struct ZoO_pipe io [const restrict static 1] ); @@ -88,7 +88,7 @@ int ZoO_knowledge_get_word const struct ZoO_knowledge k [const static 1], const ZoO_index word_ref, const ZoO_char * word [const restrict static 1], - size_t word_size [const restrict static 1], + ZoO_index word_size [const restrict static 1], const struct ZoO_pipe io [const restrict static 1] ); @@ -125,7 +125,7 @@ int ZoO_knowledge_find_following_words ( const struct ZoO_knowledge k [const static 1], const ZoO_index sequence [const restrict], - const ZoO_index sequence_length, + const size_t sequence_length, const ZoO_index markov_order, const ZoO_index * restrict following_words [const restrict static 1], const ZoO_index * restrict following_words_weights [const restrict static 1], diff --git a/src/knowledge/knowledge_finalize.c b/src/knowledge/knowledge_finalize.c index 36a7406..9628672 100644 --- a/src/knowledge/knowledge_finalize.c +++ b/src/knowledge/knowledge_finalize.c @@ -1,8 +1,4 @@ #include <stdlib.h> -#include <string.h> -#include <stdint.h> /* defines SIZE_MAX */ - -#include "../cli/cli.h" #include "knowledge.h" @@ -59,7 +55,7 @@ static void knowledge_word_finalize struct ZoO_knowledge_word w [const restrict static 1] ) { - w->word_size = 0; + w->word_length = 0; w->occurrences = 0; if (w->word != (ZoO_char *) NULL) diff --git a/src/knowledge/knowledge_learn_markov_sequence.c b/src/knowledge/knowledge_learn_markov_sequence.c index ec71254..2bd0103 100644 --- a/src/knowledge/knowledge_learn_markov_sequence.c +++ b/src/knowledge/knowledge_learn_markov_sequence.c @@ -2,7 +2,7 @@ #include <string.h> #include <stdint.h> /* defines SIZE_MAX */ -#include "../core/sequence.h" +#include "../sequence/sequence.h" #include "../pipe/pipe.h" @@ -18,15 +18,16 @@ static void set_nth_sequence const ZoO_index sequence_id ) { - /* Safe: (> k->sequences_length 1) */ if (sorted_sequence_id < (k->sequences_length - 1)) { memmove ( - /* Safe: (=< (+ sorted_sequence_id 1) k->sequences_length) */ (void *) (k->sequences_sorted + (sorted_sequence_id + 1)), (const void *) (k->sequences_sorted + sorted_sequence_id), - ((k->sequences_length - 1) - sorted_sequence_id) + ( + ((size_t) ((k->sequences_length - 1) - sorted_sequence_id)) + * sizeof(ZoO_index) + ) ); } diff --git a/src/knowledge/knowledge_learn_sequence.c b/src/knowledge/knowledge_learn_sequence.c index 7696fbc..35b6d15 100644 --- a/src/knowledge/knowledge_learn_sequence.c +++ b/src/knowledge/knowledge_learn_sequence.c @@ -2,7 +2,7 @@ #include <string.h> #include <stdint.h> /* defines SIZE_MAX */ -#include "../core/sequence.h" +#include "../sequence/sequence.h" #include "../pipe/pipe.h" @@ -15,11 +15,15 @@ static int add_following_sequence ( struct ZoO_knowledge k [const restrict static 1], const ZoO_index sequence [const restrict static 1], - const ZoO_index index, - const ZoO_index sequence_length, + const size_t index, + const size_t sequence_length, const ZoO_index markov_order, const struct ZoO_pipe io [const restrict static 1] -); +) +{ + /* TODO */ + return -1; +} /******************************************************************************/ /** LEARN PRECEDING SEQUENCE **************************************************/ @@ -28,33 +32,32 @@ static int add_preceding_sequence ( struct ZoO_knowledge k [const restrict static 1], const ZoO_index sequence [const restrict static 1], - const ZoO_index index, - const ZoO_index sequence_length, + const size_t index, + const size_t sequence_length, const ZoO_index markov_order, const struct ZoO_pipe io [const restrict static 1] ) { + /* TODO */ + return -1; } /******************************************************************************/ /** EXPORTED ******************************************************************/ /******************************************************************************/ - int ZoO_knowledge_learn_sequence ( struct ZoO_knowledge k [const restrict static 1], const ZoO_index sequence [const restrict static 1], - const ZoO_index sequence_length, + const size_t sequence_length, const ZoO_index markov_order, const struct ZoO_pipe io [const restrict static 1] ) { ZoO_index * buffer; - ZoO_index i; + size_t i; const ZoO_index buffer_length = (markov_order - 1); - /* TODO */ - for (i = 0; i < sequence_length; ++i) { k->words[sequence[i]].occurrences += 1; diff --git a/src/knowledge/knowledge_learn_word.c b/src/knowledge/knowledge_learn_word.c index e6979dc..33a2bf1 100644 --- a/src/knowledge/knowledge_learn_word.c +++ b/src/knowledge/knowledge_learn_word.c @@ -30,7 +30,7 @@ static void initialize_word ) { w->word = (const ZoO_char *) NULL; - w->word_size = 0; + w->word_length = 0; w->occurrences = 0; initialize_sequence_collection(&(w->followed)); @@ -53,7 +53,7 @@ static ZoO_char * copy_word (ZoO_char *) calloc ( - (size_t) (original_length + 1), + original_length, sizeof(ZoO_char) ); @@ -71,8 +71,6 @@ static ZoO_char * copy_word (((size_t) original_length) * sizeof(ZoO_char)) ); - result[original_length] = '\0'; - return 0; } @@ -86,7 +84,8 @@ static int reallocate_words_list if ( - (SIZE_MAX / sizeof(struct ZoO_knowledge_word)) > (size_t) k->words_length + (SIZE_MAX / sizeof(struct ZoO_knowledge_word)) + > (size_t) k->words_length ) { ZoO_S_ERROR @@ -135,7 +134,7 @@ static int reallocate_words_sorted_list * whose size is bigger than a ZoO_index. * */ /* - if ((SIZE_MAX / sizeof(ZoO_index)) > (size_t) k->words_length) + if ((SIZE_MAX / sizeof(ZoO_index)) > k->words_length) { ZoO_S_ERROR ( @@ -185,7 +184,10 @@ static void set_nth_word /* Safe: (=< (+ sorted_word_id 1) k->words_length) */ (void *) (k->words_sorted + (sorted_word_id + 1)), (const void *) (k->words_sorted + sorted_word_id), - ((k->words_length - 1) - sorted_word_id) + ( + ((size_t) ((k->words_length - 1) - sorted_word_id)) + * sizeof(ZoO_index) + ) ); } @@ -235,7 +237,7 @@ static int add_word initialize_word(k->words + word_id); k->words[word_id].word = stored_word; - k->words[word_id].word_size = ((word_length + 1) * sizeof(ZoO_char)); + k->words[word_id].word_length = word_length; if (reallocate_words_sorted_list(k, io) < 0) { @@ -257,22 +259,28 @@ int ZoO_knowledge_learn_word ( struct ZoO_knowledge k [const restrict static 1], const ZoO_char word [const restrict static 1], - const ZoO_index word_length, + const size_t word_length, ZoO_index word_id [const restrict static 1], const struct ZoO_pipe io [const restrict static 1] ) { ZoO_index sorted_id; + if (word_length >= (size_t) ZoO_INDEX_MAX) + { + ZoO_S_ERROR(io, "Word is too long to be learned."); + + return -1; + } + if ( ZoO_knowledge_find_word_id ( k, word, - (word_length * sizeof(ZoO_char)), - word_id, - io + (((size_t) word_length) * sizeof(ZoO_char)), + word_id ) == 0 ) { @@ -282,5 +290,5 @@ int ZoO_knowledge_learn_word sorted_id = *word_id; *word_id = k->words_length; - return add_word(k, word, word_length, *word_id, sorted_id, io); + return add_word(k, word, (ZoO_index) word_length, *word_id, sorted_id, io); } diff --git a/src/knowledge/knowledge_search.c b/src/knowledge/knowledge_search.c index 23aab71..4ea4572 100644 --- a/src/knowledge/knowledge_search.c +++ b/src/knowledge/knowledge_search.c @@ -2,7 +2,7 @@ #include "../core/char.h" #include "../core/index.h" -#include "../core/sequence.h" +#include "../sequence/sequence.h" #include "../pipe/pipe.h" @@ -13,7 +13,7 @@ int ZoO_knowledge_find_word_id ( const struct ZoO_knowledge k [const restrict static 1], const ZoO_char word [const restrict static 1], - const size_t word_size, + const size_t word_length, ZoO_index result [const restrict static 1] ) { @@ -40,7 +40,7 @@ int ZoO_knowledge_find_word_id { i = (current_min + ((current_max - current_min) / 2)); - cmp = ZoO_word_cmp(word, word_size, k->words[k->words_sorted[i]].word); + cmp = ZoO_word_cmp(word, word_length, k->words[k->words_sorted[i]].word); if (cmp > 0) { @@ -211,7 +211,7 @@ int ZoO_knowledge_find_following_words ( const struct ZoO_knowledge k [const static 1], const ZoO_index sequence [const restrict], - const ZoO_index sequence_length, + const size_t sequence_length, const ZoO_index markov_order, const ZoO_index * restrict following_words [const restrict static 1], const ZoO_index * restrict following_words_weights [const restrict static 1], @@ -224,14 +224,15 @@ int ZoO_knowledge_find_following_words ZoO_index i, current_min, current_max, local_sequence; const ZoO_index * restrict candidate; const ZoO_index markov_sequence_length = (markov_order - 1); - const ZoO_index sequence_offset = - ((sequence_length - markov_sequence_length) - 1); + const size_t sequence_offset = + ((sequence_length - ((size_t) markov_sequence_length)) - 1); const ZoO_index word = sequence[sequence_offset]; if (word >= k->words_length) { ZoO_S_ERROR ( + io, "Attempting to find the following words of an unknown word." ); diff --git a/src/knowledge/knowledge_types.h b/src/knowledge/knowledge_types.h index 7eafc8b..4962991 100644 --- a/src/knowledge/knowledge_types.h +++ b/src/knowledge/knowledge_types.h @@ -18,7 +18,7 @@ struct ZoO_knowledge_sequence_collection struct ZoO_knowledge_word { const ZoO_char * word; - size_t word_size; + ZoO_index word_length; ZoO_index occurrences; struct ZoO_knowledge_sequence_collection followed; struct ZoO_knowledge_sequence_collection preceded; @@ -32,7 +32,6 @@ struct ZoO_knowledge ZoO_index ** sequences; ZoO_index sequences_length; ZoO_index * sequences_sorted; - ZoO_index sequences_length; }; #endif |


