public void ProcessLargeRange(Range range, Range *subRanges) { ComputeAxisAndPivot(ref range, out var axis, out var pivot); var temps = stackalloc Range[2]; Segregate(axis, pivot, range, 2, ref temps[0], ref temps[1]); ComputeAxisAndPivot(ref temps[0], out var lAxis, out var lPivot);
public void ProcessLargeRange(Range range, Range *subRanges) { if (!UseSah) { ComputeAxisAndPivot(ref range, out int axis, out float pivot); Range *temps = stackalloc Range[2]; Segregate(axis, pivot, range, 2, ref temps[0], ref temps[1]); ComputeAxisAndPivot(ref temps[0], out int lAxis, out float lPivot);
/// <summary> /// 是否空集合 /// </summary> /// <returns>是否空集合</returns> public unsafe bool IsEmpty() { byte *indexFixed = indexs.Byte; for (Range *index = (Range *)(indexFixed + indexs.ByteSize); index != indexFixed;) { --index; if ((*index).StartIndex != (*index).EndIndex) { return(false); } } return(true); }
void CreateChildren(Range *subRanges, int numSubRanges, int parentNodeIndex, ref int freeNodeIndex, Range *rangeStack, ref int stackSize) { int4 parentData = int4.zero; for (int i = 0; i < numSubRanges; i++) { // Add child node. int childNodeIndex = freeNodeIndex++; parentData[i] = childNodeIndex; if (subRanges[i].Length > 4) { // Keep splitting the range, push it on the stack. rangeStack[stackSize] = subRanges[i]; rangeStack[stackSize++].Root = childNodeIndex; } else { Node *childNode = GetNode(childNodeIndex); childNode->IsLeaf = true; for (int pointIndex = 0; pointIndex < subRanges[i].Length; pointIndex++) { childNode->Data[pointIndex] = Points[subRanges[i].Start + pointIndex].Index; } for (int j = subRanges[i].Length; j < 4; j++) { childNode->ClearLeafData(j); } } } Node *parentNode = GetNode(parentNodeIndex); parentNode->Data = parentData; parentNode->IsInternal = true; }
void ProcessSmallRange(Range baseRange, ref int freeNodeIndex) { Range range = baseRange; ComputeAxisAndPivot(ref range, out int axis, out float pivot); SortRange(axis, ref range); Range *subRanges = stackalloc Range[4]; int hasLeftOvers = 1; do { int numSubRanges = 0; while (range.Length > 4 && numSubRanges < 3) { subRanges[numSubRanges].Start = range.Start; subRanges[numSubRanges].Length = 4; numSubRanges++; range.Start += 4; range.Length -= 4; } if (range.Length > 0) { subRanges[numSubRanges].Start = range.Start; subRanges[numSubRanges].Length = range.Length; numSubRanges++; } hasLeftOvers = 0; CreateChildren(subRanges, numSubRanges, range.Root, ref freeNodeIndex, (Range *)UnsafeUtility.AddressOf(ref range), ref hasLeftOvers); Assert.IsTrue(hasLeftOvers <= 1 /*, "Internal error"*/); } while (hasLeftOvers > 0); }
/// <summary> /// 获取哈希数据数组 /// </summary> /// <typeparam name="valueType">数据类型</typeparam> /// <param name="values">数据集合</param> /// <param name="hashs">哈希集合</param> /// <returns>哈希数据数组</returns> protected valueType[] getValues <valueType>(valueType[] values, int *hashs) { int indexBits = ((uint)values.Length).bits(); if (indexBits < defaultArrayLengthBits) { indexBits = defaultArrayLengthBits; } else if ((1 << (indexBits - 1)) == values.Length) { --indexBits; } indexAnd = 1 << indexBits; indexs = Unmanaged.GetSize64(indexAnd-- *sizeof(Range), true); Range *indexFixed = (Range *)indexs.Data; for (int *hash = hashs + values.Length; hash != hashs; ++indexFixed[*--hash & indexAnd].StartIndex) { ; } int startIndex = 0; for (Range *index = indexFixed, endIndex = indexFixed + indexAnd + 1; index != endIndex; ++index) { int nextIndex = startIndex + (*index).StartIndex; (*index).StartIndex = (*index).EndIndex = startIndex; startIndex = nextIndex; } valueType[] newValues = new valueType[values.Length]; foreach (valueType value in values) { newValues[indexFixed[*hashs++ & indexAnd].EndIndex++] = value; } //for (int index = 0; index != values.Length; newValues[indexFixed[*hashs++ & indexAnd].EndIndex++] = values[index++]) ; return(newValues); }
public override Task <SignatureHelp> Handle(SignatureHelpParams request, CancellationToken cancellationToken) { var currentHash = Hash.StringHash(request.TextDocument.Uri.GetFileSystemPath()); var pos = request.Position; TreeSitter.GetSignature(currentHash, pos.Line, pos.Character, out var signatureArrayPtr, out var parameterCount, out var activeParameter, out var errorCount, out var errorRanges); if (signatureArrayPtr.ToInt64() == 0) { return(Task.FromResult(new SignatureHelp())); } var signaturePtr = System.Runtime.InteropServices.Marshal.ReadIntPtr(signatureArrayPtr); var signature = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(signaturePtr); SignatureInformation info = new SignatureInformation(); info.Label = signature; var paramList = new List <ParameterInformation>(); if (parameterCount > 0) { for (int i = 0; i < parameterCount; i++) { var paramInfo = new ParameterInformation(); var paramPtr = System.Runtime.InteropServices.Marshal.ReadIntPtr(signatureArrayPtr + 8 * (i + 1));; paramInfo.Label = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(paramPtr); paramList.Add(paramInfo); } } info.Parameters = new Container <ParameterInformation>(paramList); SignatureHelp help = new SignatureHelp(); help.Signatures = new Container <SignatureInformation>(info); help.ActiveParameter = activeParameter; help.ActiveSignature = 0; if (errorCount > 0) { List <Diagnostic> diagnostics = new List <Diagnostic>(); PublishDiagnosticsParams diagnosticsParams = new PublishDiagnosticsParams(); diagnosticsParams.Uri = request.TextDocument.Uri; unsafe { for (int i = 0; i < errorCount; i++) { Range * errors = (Range *)errorRanges; var error = errors[i]; Diagnostic diagnostic = new Diagnostic(); diagnostic.Message = "Extra argument"; diagnostic.Range = new OmniSharp.Extensions.LanguageServer.Protocol.Models.Range( new Position(error.startLine, error.startCol), new Position(error.endLine, error.endCol)); diagnostics.Add(diagnostic); } } diagnoser.Add(request.TextDocument.Uri, 1, diagnostics); } else { diagnoser.Add(request.TextDocument.Uri, 1, new List <Diagnostic>()); } return(Task.FromResult(help)); }