public static int GetNodeSize(kowhai_node_t[] descriptor, out int size) { GCHandle h = GCHandle.Alloc(descriptor, GCHandleType.Pinned); int result = kowhai_get_node_size(h.AddrOfPinnedObject(), out size); h.Free(); return result; }
public static int GetNode(kowhai_node_t[] descriptor, kowhai_symbol_t[] symbols, out int offset, out kowhai_node_t node) { GCHandle hDesc = GCHandle.Alloc(descriptor, GCHandleType.Pinned); GCHandle hSyms = GCHandle.Alloc(symbols, GCHandleType.Pinned); IntPtr targetNode = IntPtr.Zero; int result = kowhai_get_node(hDesc.AddrOfPinnedObject(), symbols.Length, hSyms.AddrOfPinnedObject(), out offset, ref targetNode); hSyms.Free(); hDesc.Free(); node = (kowhai_node_t)Marshal.PtrToStructure(targetNode, typeof(kowhai_node_t)); return result; }
public static kowhai_symbol_t[] GetSymbolPath(kowhai_node_t[] descriptor, kowhai_node_t node, int32_t nodeIndex, uint16_t[] arrayIndexes) { Stack<kowhai_symbol_t> syms = new Stack<kowhai_symbol_t>(); for (int i = 0; i <= nodeIndex; i++) { kowhai_node_t newNode = descriptor[i]; if (i == nodeIndex) syms.Push(new kowhai_symbol_t(newNode.symbol, arrayIndexes[syms.Count])); else if (newNode.type == BRANCH) syms.Push(new kowhai_symbol_t(newNode.symbol, arrayIndexes[syms.Count])); else if (newNode.type == BRANCH_END) syms.Pop(); } kowhai_symbol_t[] result = syms.ToArray(); Array.Reverse(result); return result; }
public Tree(kowhai_node_t[] desc, byte[] data) { Descriptor = desc; Data = data; }