private void SelectEntities(SimpleEntity mainEntity, IEnumerable <string> expressions) { //сущности текущего типа, подлежащие добавлению в mainEntity List <SimpleEntity> entitiesWithCurrentTypeToAdd = new List <SimpleEntity>(); bool isEmptyMain = string.IsNullOrEmpty(mainEntity.Type); foreach (string type in expressions) { EntityExpression expression = _expressions.GetExpression(type); if ((expression.SelectionType == SelectionType.False) || (isEmptyMain && (expression.SelectionType == SelectionType.Child))) { continue; } UseExpression(mainEntity, expression); } foreach (SimpleEntity entity in mainEntity.Children) { SelectEntities(entity, _expressions.GetExpression(entity.Type).UsedExpressions); } }
/// <summary> /// Поиск индекса Child'а, ближайшего к месту вставки entity /// </summary> /// <param name="entity">Entity для вставки</param> /// <param name="children">Дети</param> /// <returns>индекса Child'а, ближайшего к месту вставки entity</returns> private static int FindNearestChildIndex(SimpleEntity entity, List <SimpleEntity> children) { int position = entity.StartPosition; int leftBorder = 0; int rightBorder = children.Count; int middle = 0; while (leftBorder < rightBorder) { middle = leftBorder + (rightBorder - leftBorder) / 2; if (position <= children[middle].StartPosition) { rightBorder = middle; } else { leftBorder = middle + 1; } } return(middle); }
/// <summary> /// Получить пересечения, используя бинарный поиск. /// </summary> /// <param name="mainEntity"></param> /// <param name="entity"></param> /// <returns></returns> private List <SimpleEntity> GetIntersectionBinaryAlgorithm(SimpleEntity mainEntity, SimpleEntity entity) { List <SimpleEntity> children = mainEntity.Children; int nearestChildIndex = FindNearestChildIndex(entity, children); return(GetIntersectionsUsingNearestChild(entity, children, nearestChildIndex)); }
/// <summary> /// Получить пересечения /// </summary> /// <param name="mainEntity"></param> /// <param name="entity"></param> /// <returns></returns> private List <SimpleEntity> GetIntersections(SimpleEntity mainEntity, SimpleEntity entity) { return(GetIntersectionBinaryAlgorithm(mainEntity, entity)); }