Hi,
I just started to learn Mojo. I tried to implement Trie data structure, but I have a problem with my implementation. Following is the simple code:
struct TrieNode(Copyable, Movable, ExplicitlyCopyable):
var children: List[Optional[UnsafePointer[TrieNode]]]
var id: Int
var char: Int
fn __init__(out self):
self.children = List[Optional[UnsafePointer[TrieNode]]]()
for _ in range(256):
self.children.append(None)
self.id = 0
self.char = 0
struct Trie(Copyable, Movable, ExplicitlyCopyable):
var root: TrieNode
fn __init__(out self):
# Allocate memory for the root node and call its initializer.
self.root = UnsafePointer[TrieNode].alloc(1)
self.root.init_pointee_move(TrieNode())
And this is the error message:
(trie) (base) cahya@bintang:~/mojo/trie$ mojo trie_test.mojo
~/mojo/trie/trie_test.mojo:20:50: error: cannot implicitly convert 'UnsafePointer[TrieNode, origin={}]' value to 'TrieNode'
self.root = UnsafePointer[TrieNode].alloc(1)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
~/mojo/trie/trie_test.mojo:21:18: error: 'TrieNode' value has no attribute 'init_pointee_move'
self.root.init_pointee_move(TrieNode())
~~~~~~~~~^
mojo: error: failed to parse the provided Mojo source module