Skip to content

Commit

Permalink
Make node value immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Wootten authored and Jeremy Wootten committed Jan 31, 2025
1 parent 87c748d commit 09bfef4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 7 additions & 1 deletion plugins/word-completion/prefix-tree-node.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@

public class Scratch.Plugins.PrefixNode : Object{
public GLib.List<PrefixNode> children;
public unichar value { get; set; }
public unichar value { get; construct; }

public PrefixNode (unichar c = '\0') {
Object (
value: c
);
}

construct {
children = new List<PrefixNode> ();
Expand Down
8 changes: 2 additions & 6 deletions plugins/word-completion/prefix-tree.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ namespace Scratch.Plugins {
}

public void clear () {
root = new PrefixNode () {
value = '\0'
};
root = new PrefixNode ();
}

public void insert (string word) {
Expand Down Expand Up @@ -38,9 +36,7 @@ namespace Scratch.Plugins {
}
}

var new_child = new PrefixNode () {
value = curr
};
var new_child = new PrefixNode (curr);
node.children.insert_sorted (new_child, (c1, c2) => {
if (c1.value > c2.value) {
return 1;
Expand Down

0 comments on commit 09bfef4

Please sign in to comment.