From a517f0d6380df60f735f4e6a78a93ecdd91ec70e Mon Sep 17 00:00:00 2001 From: an Date: Sat, 24 Aug 2019 09:06:39 +0200 Subject: [PATCH] markov: fixed severe bug in Shift() --- modules/markov.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/markov.go b/modules/markov.go index 3b32102..876dbf3 100644 --- a/modules/markov.go +++ b/modules/markov.go @@ -129,8 +129,12 @@ func (p MarkovPrefix) String() string { // Shift removes the first word from the Prefix and appends the given word. func (p MarkovPrefix) Shift(word string) { - copy(p, p[1:]) - p[len(p)-1] = word + if len(p) < *markovPrefixLen { + p = append(p, word) + } else { + copy(p, p[1:]) + p[len(p)-1] = word + } } // MarkovChain contains a map ("chain") of prefixes to a list of suffixes.