public unsafe AutomataNode SearchNext(ref byte *p, ref int rest) { var key = AutomataKeyGen.GetKey(ref p, 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); }
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); } } }