コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="indexInSymbolTarget"></param>
        /// <param name="seriesMatch"></param>
        /// <returns>whether the match succeeded or not</returns>
        public bool MatchesBackwards(
            NativeMultipleHashSets.HashSetSlice includedSymbolSet,
            int indexInSymbolTarget,
            SymbolSeriesPrefixMatcher seriesMatch,
            SymbolString <float> symbolString,
            int firstParameterCopyIndex,
            NativeArray <float> parameterCopyMemory,
            out byte paramsCopiedToMem)
        {
            indexInSymbolTarget--;
            int matchingIndex = seriesMatch.graphNodeMemSpace.length - 1;

            paramsCopiedToMem = 0;

            for (; matchingIndex >= 0 && indexInSymbolTarget >= 0;)
            {
                var symbolToMatch = nativeRuleData.prefixMatcherSymbols[matchingIndex + seriesMatch.graphNodeMemSpace.index];
                while (indexInSymbolTarget >= 0)
                {
                    var currentSymbol = symbolString.symbols[indexInSymbolTarget];
                    if (!includedSymbolSet.Contains(currentSymbol) || currentSymbol == branchOpenSymbol)
                    {
                        indexInSymbolTarget--;
                    }
                    else if (currentSymbol == branchCloseSymbol)
                    {
                        indexInSymbolTarget = FindOpeningBranchIndexReadonly(indexInSymbolTarget) - 1;
                    }
                    else if (currentSymbol == symbolToMatch.targetSymbol &&
                             symbolToMatch.parameterLength == symbolString.parameters[indexInSymbolTarget].length)
                    {
                        // copy the parameters in reverse order, so they can be reversed in-place at end
                        //  on success
                        var paramIndexing = symbolString.parameters[indexInSymbolTarget];
                        for (int i = paramIndexing.length - 1; i >= 0; i--)
                        {
                            parameterCopyMemory[paramsCopiedToMem + firstParameterCopyIndex] = symbolString.parameters[paramIndexing, i];
                            paramsCopiedToMem++;
                        }

                        indexInSymbolTarget--;
                        matchingIndex--;
                        break;
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            if (matchingIndex == -1)
            {
                ReverseRange(parameterCopyMemory, firstParameterCopyIndex, paramsCopiedToMem);
                return(true);
            }
            return(false);
        }
コード例 #2
0
        public SymbolSeriesPrefixMatcher BuildIntoManagedMemory(
            SystemLevelRuleNativeData nativeData,
            SymbolSeriesMatcherNativeDataWriter dataWriter)
        {
            var matcher = new SymbolSeriesPrefixMatcher();

            matcher.graphNodeMemSpace = new JaggedIndexing
            {
                index  = dataWriter.indexInPrefixNodes,
                length = (ushort)RequiredNodeMemorySpace
            };
            dataWriter.indexInPrefixNodes += RequiredNodeMemorySpace;

            for (int i = 0; i < targetSymbolSeries.Length; i++)
            {
                var symbol = targetSymbolSeries[i].AsBlittable();
                nativeData.prefixMatcherSymbols[i + matcher.graphNodeMemSpace.index] = symbol;
            }

            matcher.IsValid = targetSymbolSeries.Length > 0;

            return(matcher);
        }