Exemplo n.º 1
0
    void AddToDatabase(PrefixWord prefix, SuffixWord suffix)
    {
        string prefixValue = prefix.GetConcatenatedPrefix();

        if (prefixValue == "*|*" && suffix.value == "*")
        {
            // Don't add [*|* -> *]
            return;
        }

        int index = table.database.FindIndex(p => (p.prefix == prefixValue));

        if (index != -1)
        {
            table.database[index].AddSuffix(suffix);
        }
        else
        {
            table.database.Add(new PreSuffixWordEntry(prefixValue, suffix));
        }
    }
Exemplo n.º 2
0
    public SuffixWord GetSuffixOf(PrefixWord prefix)
    {
        int index = database.FindIndex(p => (p.prefix == prefix.GetConcatenatedPrefix()));

        if (index != -1)
        {
            int multiplicitySum = database[index].suffixes.Select(m => m.multiplicity).ToArray().Sum();
            int roll            = Random.Range(0, multiplicitySum);

            int cumulative = 0;
            for (int i = 0; i < database[index].suffixes.Count; i++)
            {
                SuffixWord suffix = database[index].suffixes[i];
                cumulative += suffix.multiplicity;

                if (roll < cumulative)
                {
                    return(suffix);
                }
            }
        }

        return(new SuffixWord("*"));
    }