cleanups to startup code and goroutine code
This commit is contained in:
+6
-10
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Amsterdam Web Communities System
|
||||
* Copyright (c) 2025 Erbosoft Metaverse Design Solutions, All Rights Reserved
|
||||
* Copyright (c) 2025-2026 Erbosoft Metaverse Design Solutions, All Rights Reserved
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
@@ -44,17 +44,17 @@ func (d *TrieDictionary) Size() int {
|
||||
// CheckWord returns true if a word is in the dictionary, false if not.
|
||||
func (d *TrieDictionary) CheckWord(word string) bool {
|
||||
d.mutex.Lock()
|
||||
defer d.mutex.Unlock()
|
||||
_, rc := d.trie.Find(strings.ToLower(word))
|
||||
d.mutex.Unlock()
|
||||
return rc
|
||||
}
|
||||
|
||||
// AddWord adds a new word to the dictionary.
|
||||
func (d *TrieDictionary) AddWord(word string) {
|
||||
d.mutex.Lock()
|
||||
defer d.mutex.Unlock()
|
||||
d.trie.Add(strings.ToLower(word), true)
|
||||
d.count++
|
||||
d.mutex.Unlock()
|
||||
}
|
||||
|
||||
// DelWord deletes a word from the dictionary.
|
||||
@@ -89,12 +89,8 @@ func loadDict(d *TrieDictionary, words []byte) {
|
||||
|
||||
// LoadTrieDict creates a TrieDictionary from a byte array that represents a word list (one word per line).
|
||||
func LoadTrieDict(words []byte) *TrieDictionary {
|
||||
rc := TrieDictionary{
|
||||
loaded: atomic.Bool{},
|
||||
trie: trie.New(),
|
||||
count: 0,
|
||||
}
|
||||
rc := new(TrieDictionary{loaded: atomic.Bool{}, trie: trie.New(), count: 0})
|
||||
rc.loaded.Store(false)
|
||||
go loadDict(&rc, words)
|
||||
return &rc
|
||||
go loadDict(rc, words)
|
||||
return rc
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user