コード例 #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 (int 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);
            }
コード例 #2
0
        public unsafe void Add(byte[] bytes, int value)
        {
            var offset = 0;

            var node = root;

            var rest = bytes.Length;

            while (rest != 0)
            {
                var key = AutomataKeyGen.GetKeySafe(bytes, ref offset, ref rest);

                if (rest == 0)
                {
                    node = node.Add(key, value, Encoding.UTF8.GetString(bytes));
                }
                else
                {
                    node = node.Add(key);
                }
            }
        }
コード例 #3
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);

                    if (rest == 0)
                    {
                        node = node.Add(key, value, StringEncoding.UTF8.GetString(bytes));
                    }
                    else
                    {
                        node = node.Add(key);
                    }
                }
            }
        }