Skip to content

Commit

Permalink
Merge branch 'master' into jeremypw/rework-word-completion/plugin-cle…
Browse files Browse the repository at this point in the history
…anup
  • Loading branch information
jeremypw authored Feb 1, 2025
2 parents 49fc736 + f77f5f5 commit 21c2459
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
1 change: 1 addition & 0 deletions plugins/word-completion/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module_name = 'word-completion'

module_files = [
'prefix-tree.vala',
'prefix-tree-node.vala',
'completion-provider.vala',
'engine.vala',
'plugin.vala'
Expand Down
35 changes: 35 additions & 0 deletions plugins/word-completion/prefix-tree-node.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2024 elementary, Inc. <https://elementary.io>
* 2011 Lucas Baudin <[email protected]>
* *
* 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<PrefixNode> children;
public unichar value { get; construct; }

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

construct {
children = new List<PrefixNode> ();
}
}
17 changes: 2 additions & 15 deletions plugins/word-completion/prefix-tree.vala
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@

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

construct {
children = new List<PrefixNode> ();
}
}

public class PrefixTree : Object {
private PrefixNode root;

Expand All @@ -17,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 @@ -47,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 21c2459

Please sign in to comment.