Exemple #1
0
            public unsafe AutomataNode SearchNextSafe(byte[] p, ref int offset, ref int rest)
            {
                var key = AutomataKeyGen.GetKeySafe(p, ref offset, ref rest);

                if (_count < 4)
                {
                    // linear search
                    for (var i = 0; i < _count; i++)
                    {
                        if (_nextKeys[i] == key)
                        {
                            return(_nexts[i]);
                        }
                    }
                }
                else
                {
                    // binary search
                    var index = BinarySearch(_nextKeys, 0, _count, key);
                    if (index >= 0)
                    {
                        return(_nexts[index]);
                    }
                }

                return(null);
            }
Exemple #2
0
        public unsafe void Add(byte[] bytes, int value)
        {
            fixed(byte *buffer = &bytes[0])
            {
                var node = _root;

                var p    = buffer;
                var rest = bytes.Length;

                while (rest != 0)
                {
                    var key = AutomataKeyGen.GetKey(ref p, ref rest);

                    node = rest == 0
                                                ? node.Add(key, value, Encoding.UTF8.GetString(bytes))
                                                : node.Add(key);
                }
            }
        }