Pliant icon indicating copy to clipboard operation
Pliant copied to clipboard

add disambiguation algorithm for iterative tree traversal

Open patrickhuber opened this issue 7 years ago • 0 comments

Given that the parse forest is a binary tree, a dictionary can be passed into a disambiguation algorithm that tells each node which child to traverse. The disambiguation algorithm is responsible for tracking the current node index which increments every time the function is called.

namespace Pliant.Forest
{
    public class ChildSelectDisambiguationAlgorithm : IForestDisambiguationAlgorithm
    {
        IList<int> _childIndexes ;
        int _index ;

        public IList<int> ChildIndexes { get { return _childIndexes; } }

        public ChildSelectDisambiguationAlgorithm()
        {
              _childIndexes = new List<int>();
              _index = 0;
        }
        public ChildSelectDisambiguationAlgorithm(IEnumerable<int> childIndexes)
        {
              _childIndexes = new List<int>(childIndexes);
              _index = 0;
        }
        public IAndForestNode GetCurrentAndNode(IInternalForestNode internalNode)
        {
             _index ++;
             childIndex = _childIndexes [index] ;
             return internalNode.Children[childIndex];
        }
    }
}

patrickhuber avatar Nov 29 '18 19:11 patrickhuber