Пример #1
0
        public bool ActOnCells(TextAsset textAsset, CellVisitor cellVisitor, out TextAssetTableResult tableResult)
        {
            tableResult = new TextAssetTableResult();
            var i = 0;

            foreach (var row in SplitTableToRows(textAsset))
            {
                tableResult.Rows++;
                var colCount = 0;

                var j = 0;
                foreach (var col in SplitRowToCells(row))
                {
                    colCount++;
                    if (cellVisitor(i, j, col))
                    {
                        tableResult.CellsActedOn++;
                    }

                    j++;
                }

                tableResult.Cols = Math.Max(tableResult.Cols, colCount);
                i++;
            }

            return(tableResult.CellsActedOn > 0);
        }
Пример #2
0
 public void Visit(CellVisitor visitor)
 {
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < height; y++)
         {
             visitor(cells[x, y]);
         }
     }
 }
Пример #3
0
 override public void Accept(ModelComponentVisitor visitor)
 {
     if (visitor is CellVisitor)
     {
         CellVisitor cellVisitor = (CellVisitor)visitor;
         cellVisitor.Visit(this);
     }
     else
     {
         base.Accept(visitor);
     }
 }
Пример #4
0
    // Visits all (cell_id, label) pairs in the given index that intersect the
    // given S2CellUnion "target", terminating early if the given CellVisitor
    // function returns false (in which case VisitIntersectingCells returns false
    // as well).  Each (cell_id, label) pair in the index is visited at most
    // once.  (If the index contains duplicates, then each copy is visited.)
    public bool VisitIntersectingCells(S2CellUnion target, CellVisitor visitor)
    {
        if (!target.CellIds.Any())
        {
            return(true);
        }

        var contents = new ContentsEnumerator(this);

        var targetIndex = 0;
        var targetLimit = target.CellIds.Count;
        var rangeIndex  = 0;

        do
        {
            var limitId = range_nodes_[rangeIndex + 1].StartId;
            if (limitId <= target.CellIds[targetIndex].RangeMin())
            {
                // Only seek when necessary.
                var rangeTarget = target.CellIds[targetIndex].RangeMin();
                rangeIndex = range_nodes_.GetUpperBound(new RangeNode(rangeTarget, -1)) - 1;
            }
            for (; range_nodes_[rangeIndex].StartId <= target.CellIds[targetIndex].RangeMax(); rangeIndex++)
            {
                var rNode = range_nodes_[rangeIndex];
                contents.StartUnion(rNode);
                while (contents.MoveNext())
                {
                    if (!visitor(contents.Current.CellId, contents.Current.Label))
                    {
                        return(false);
                    }
                }
            }
            // Check whether the next target cell is also contained by the leaf cell
            // range that we just processed.  If so, we can skip over all such cells
            // using binary search.  This speeds up benchmarks by between 2x and 10x
            // when the average number of intersecting cells is small (< 1).
            if (++targetIndex < targetLimit && target.CellIds[targetIndex].RangeMax() < range_nodes_[rangeIndex].StartId)
            {
                // Skip to the first target cell that extends past the previous range.
                targetIndex = target.CellIds.GetLowerBound(range_nodes_[rangeIndex].StartId, targetIndex + 1, targetLimit);
                if (target.CellIds[targetIndex - 1].RangeMax() >= range_nodes_[rangeIndex].StartId)
                {
                    --targetIndex;
                }
            }
        } while (targetIndex < targetLimit);
        return(true);
    }
Пример #5
0
 public bool accept(CellVisitor visitor)
 {
     return visitor.visit(this);
 }
Пример #6
0
 public bool accept(CellVisitor visitor)
 {
     return(visitor.visit(this));
 }
Пример #7
0
 public Cell(CellVisitor visitor)
 {
     Visitor = visitor;
 }