From 87c748d4c36c457f10c0bf28a909ad1e1819ed93 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 31 Jan 2025 11:17:03 +0000 Subject: [PATCH 1/3] Move prefix tree node class into separate file --- plugins/word-completion/meson.build | 1 + plugins/word-completion/prefix-tree-node.vala | 29 +++++++++++++++++++ plugins/word-completion/prefix-tree.vala | 9 ------ 3 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 plugins/word-completion/prefix-tree-node.vala diff --git a/plugins/word-completion/meson.build b/plugins/word-completion/meson.build index 247b0e60ad..23a75eee23 100644 --- a/plugins/word-completion/meson.build +++ b/plugins/word-completion/meson.build @@ -2,6 +2,7 @@ module_name = 'word-completion' module_files = [ 'prefix-tree.vala', + 'prefix-tree-node.vala', 'completion-provider.vala', 'engine.vala', 'plugin.vala' diff --git a/plugins/word-completion/prefix-tree-node.vala b/plugins/word-completion/prefix-tree-node.vala new file mode 100644 index 0000000000..01d19f14c4 --- /dev/null +++ b/plugins/word-completion/prefix-tree-node.vala @@ -0,0 +1,29 @@ +/* + * Copyright 2024 elementary, Inc. + * 2011 Lucas Baudin + * * + * This is a free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; see the file COPYING. If not, + * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +public class Scratch.Plugins.PrefixNode : Object{ + public GLib.List children; + public unichar value { get; set; } + + construct { + children = new List (); + } +} diff --git a/plugins/word-completion/prefix-tree.vala b/plugins/word-completion/prefix-tree.vala index ea5ca2d414..519574c71d 100644 --- a/plugins/word-completion/prefix-tree.vala +++ b/plugins/word-completion/prefix-tree.vala @@ -1,14 +1,5 @@ namespace Scratch.Plugins { - private class PrefixNode : Object { - public GLib.List children; - public unichar value { get; set; } - - construct { - children = new List (); - } - } - public class PrefixTree : Object { private PrefixNode root; From 09bfef42fc2e454483a3bb13c14087376a149d7a Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 31 Jan 2025 11:23:13 +0000 Subject: [PATCH 2/3] Make node value immutable --- plugins/word-completion/prefix-tree-node.vala | 8 +++++++- plugins/word-completion/prefix-tree.vala | 8 ++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/word-completion/prefix-tree-node.vala b/plugins/word-completion/prefix-tree-node.vala index 01d19f14c4..21e983a409 100644 --- a/plugins/word-completion/prefix-tree-node.vala +++ b/plugins/word-completion/prefix-tree-node.vala @@ -21,7 +21,13 @@ public class Scratch.Plugins.PrefixNode : Object{ public GLib.List children; - public unichar value { get; set; } + public unichar value { get; construct; } + + public PrefixNode (unichar c = '\0') { + Object ( + value: c + ); + } construct { children = new List (); diff --git a/plugins/word-completion/prefix-tree.vala b/plugins/word-completion/prefix-tree.vala index 519574c71d..28681f6ea8 100644 --- a/plugins/word-completion/prefix-tree.vala +++ b/plugins/word-completion/prefix-tree.vala @@ -8,9 +8,7 @@ namespace Scratch.Plugins { } public void clear () { - root = new PrefixNode () { - value = '\0' - }; + root = new PrefixNode (); } public void insert (string word) { @@ -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; From 0f1e434ca48d6cdd5501925c1fd6d27f8e72cd9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Fri, 31 Jan 2025 10:36:22 -0800 Subject: [PATCH 3/3] Update prefix-tree-node.vala --- plugins/word-completion/prefix-tree-node.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/word-completion/prefix-tree-node.vala b/plugins/word-completion/prefix-tree-node.vala index 21e983a409..89da8d0c6b 100644 --- a/plugins/word-completion/prefix-tree-node.vala +++ b/plugins/word-completion/prefix-tree-node.vala @@ -19,7 +19,7 @@ * */ -public class Scratch.Plugins.PrefixNode : Object{ +public class Scratch.Plugins.PrefixNode : Object { public GLib.List children; public unichar value { get; construct; }