|
| 1 | +/* |
| 2 | + * Copyright 2024 elementary, Inc. <https://elementary.io> |
| 3 | + * 2011 Lucas Baudin <xapantu@gmail.com> |
| 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 enum NodeType { |
| 24 | + ROOT, |
| 25 | + CHAR, |
| 26 | + WORD_END |
| 27 | + } |
| 28 | + |
| 29 | + private const unichar WORD_END_CHAR = '\0'; |
| 30 | + private uint occurrences; // Only used for WORD_END nodes |
| 31 | + |
| 32 | + public unichar uc { get; construct; } |
| 33 | + public NodeType node_type { get; construct; } |
| 34 | + public PrefixNode? parent { get; construct; } |
| 35 | + public unichar value { get; construct; } |
| 36 | + |
| 37 | + public Gee.ArrayList<PrefixNode> children; |
| 38 | + |
| 39 | + public PrefixNode.from_unichar (unichar c, PrefixNode? _parent) requires (c != WORD_END_CHAR) { |
| 40 | + Object ( |
| 41 | + value: c, |
| 42 | + parent: _parent, |
| 43 | + uc: c, |
| 44 | + node_type: NodeType.CHAR |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + public PrefixNode.root () { |
| 49 | + Object ( |
| 50 | + parent: null, |
| 51 | + uc: WORD_END_CHAR, |
| 52 | + node_type: NodeType.ROOT |
| 53 | + ); |
| 54 | + } |
| 55 | + |
| 56 | + public PrefixNode.word_end (PrefixNode _parent) { |
| 57 | + Object ( |
| 58 | + parent: _parent, |
| 59 | + uc: WORD_END_CHAR, |
| 60 | + node_type: NodeType.WORD_END |
| 61 | + ); |
| 62 | + |
| 63 | + occurrences = 1; |
| 64 | + } |
| 65 | + |
| 66 | + construct { |
| 67 | + children = new Gee.ArrayList<PrefixNode> (); |
| 68 | + } |
| 69 | +} |
0 commit comments