0

so i wrote a code to construct a dawg. i want to findout if a word exist in a language or not? after a lot of search i findout best way is to use dawg. here

public class DawgNode
{
    public DawgNode(int id)
    {
        Id = id;
    }
    public int Id { get; set; }

    public bool Final { get; set; }

    public Dictionary<char, DawgNode> Edges { get; set; } = new Dictionary<char, DawgNode>();

    public string Str()
    {
        var arr = new List<string>();
        if (Final) arr.Add("1");
        else arr.Add("0");
        foreach (var e in Edges)
        {
            arr.Add(e.Key.ToString());
            arr.Add(e.Value.Id.ToString());
        }
        return string.Join("-", arr);
    }
}

whats the best way to look up if a word exist. consider i want to implement scrabble game in a react native app. i understand number of nodes can be minimized, but what's the trick. 1- saving nodes and edges in seperated files? how? 2- convert every time a big text into a dawg and search in it? please help

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • I would have a Set of words and use `if (words.contains(word))` – Peter Lawrey Oct 16 '18 at 14:45
  • there would be no problem if your set have 100 thousands of words? because the language i work on it have even more words? – shahrooz.bazrafshan Oct 17 '18 at 15:08
  • HashSet works well up to about one billion elements. After that, it doesn't scale so well due to the limited 32-bit hashCode() and the size of the underlying array. It is builtin and well tested over the last 20 years ;) – Peter Lawrey Oct 17 '18 at 17:11

0 Answers0