Skip to content

Commit f77f5f5

Browse files
authored
Rework word completion: Split out PrefixNode class (#1529)
1 parent 6056e9a commit f77f5f5

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

plugins/word-completion/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module_name = 'word-completion'
22

33
module_files = [
44
'prefix-tree.vala',
5+
'prefix-tree-node.vala',
56
'completion-provider.vala',
67
'engine.vala',
78
'plugin.vala'
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2024 elementary, Inc. <https://elementary.io>
3+
* 2011 Lucas Baudin <[email protected]>
4+
* *
5+
* This is a free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU General Public License as
7+
* published by the Free Software Foundation; either version 2 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public
16+
* License along with this program; see the file COPYING. If not,
17+
* write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18+
* Boston, MA 02110-1301 USA.
19+
*
20+
*/
21+
22+
public class Scratch.Plugins.PrefixNode : Object {
23+
public GLib.List<PrefixNode> children;
24+
public unichar value { get; construct; }
25+
26+
public PrefixNode (unichar c = '\0') {
27+
Object (
28+
value: c
29+
);
30+
}
31+
32+
construct {
33+
children = new List<PrefixNode> ();
34+
}
35+
}

plugins/word-completion/prefix-tree.vala

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11

22
namespace Scratch.Plugins {
3-
private class PrefixNode : Object {
4-
public GLib.List<PrefixNode> children;
5-
public unichar value { get; set; }
6-
7-
construct {
8-
children = new List<PrefixNode> ();
9-
}
10-
}
11-
123
public class PrefixTree : Object {
134
private PrefixNode root;
145

@@ -17,9 +8,7 @@ namespace Scratch.Plugins {
178
}
189

1910
public void clear () {
20-
root = new PrefixNode () {
21-
value = '\0'
22-
};
11+
root = new PrefixNode ();
2312
}
2413

2514
public void insert (string word) {
@@ -47,9 +36,7 @@ namespace Scratch.Plugins {
4736
}
4837
}
4938

50-
var new_child = new PrefixNode () {
51-
value = curr
52-
};
39+
var new_child = new PrefixNode (curr);
5340
node.children.insert_sorted (new_child, (c1, c2) => {
5441
if (c1.value > c2.value) {
5542
return 1;

0 commit comments

Comments
 (0)