Example #1
0
  Space operator()( int color )
  {
    Space base, sub, margin;

    for ( typename Space::const_iterator it = base_.begin()
        ; it != base_.end(); ++it
        )
    {
      typename Space::const_point pt( it );

      if ( color_[ pt.index ] == color ) base.join( pt.element );
    }
    for ( typename Space::const_iterator it = base.begin()
        ; it != base.end(); ++it
        )
    {
      typename Space::const_point pt0( it );
#ifdef ELAI_USE_C11
      const Space&& adj = std::move( adjacent_( pt0.element ) );
#else
      const Space adj = adjacent_( pt0.element );
#endif

      sub.join( Element( pt0.element, color ) );
      for ( typename Space::const_iterator jt = adj.begin()
          ; jt != adj.end(); ++jt
          )
      {
        typename Space::const_point pt( jt );

        if ( base.contain( pt.element ) || margin.contain( Element( pt.element, color ) ) ) continue;

        int c = color_[ base_.index( pt.element ) ];

        margin.join( Element( pt.element, color ), Element( pt.element, c ) );
      }
    }

    return sub | margin;
  }
NS_IMETHODIMP
DOMSVGPathSegList::RemoveItem(PRUint32 aIndex,
                              nsIDOMSVGPathSeg **_retval)
{
    *_retval = nsnull;
    if (IsAnimValList()) {
        return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
    }

    if (aIndex >= Length()) {
        return NS_ERROR_DOM_INDEX_SIZE_ERR;
    }
    // We have to return the removed item, so make sure it exists:
    EnsureItemAt(aIndex);

    // Notify the DOM item of removal *before* modifying the lists so that the
    // DOM item can copy its *old* value:
    ItemAt(aIndex)->RemovingFromList();
    NS_ADDREF(*_retval = ItemAt(aIndex));

    PRUint32 internalIndex = mItems[aIndex].mInternalDataIndex;
    PRUint32 segType = SVGPathSegUtils::DecodeType(InternalList().mData[internalIndex]);
    PRUint32 argCount = SVGPathSegUtils::ArgCountForType(segType);

    // Now that we know we're removing, keep animVal list in sync as necessary.
    // Do this *before* touching InternalList() so the removed item can get its
    // internal value.
    MaybeRemoveItemFromAnimValListAt(aIndex, argCount);

    InternalList().mData.RemoveElementsAt(internalIndex, 1 + argCount);
    mItems.RemoveElementAt(aIndex);

    UpdateListIndicesFromIndex(aIndex, -(argCount + 1));

    Element()->DidChangePathSegList(true);
    if (AttrIsAnimating()) {
        Element()->AnimationNeedsResample();
    }
    return NS_OK;
}
Example #3
0
// Reduces all elements in a column except the diagonal element
// Returns 0 on success, 1 if the column cannot be reduced
int Matrix::ReduceColumn(int column, Matrix &inverse)
{
	// loop variable for working down column
	int row, pivot = column;

	// find the first non-zero element in the column
	// that is not above the diagonal
	for (row = pivot; row < 4; row++)
		if (fabs(Element(row, pivot)) > ERROR_TOLERANCE)
			break;

	// if we didn't find one, return an error code
	if (row == 4) return 1;

	// if we did, but it wasn't on the diagonal, swap with the pivot row
	// this makes sure we never get divide by zero errors
	if (row != pivot)
	{
		SwapRows(pivot, row);
		inverse.SwapRows(pivot, row);
	}

	// now scale the pivot row so the pivot element is one
	float scaleFactor = 1.0 / Element(pivot, pivot);
	ScaleRow(pivot, scaleFactor);
	inverse.ScaleRow(pivot, scaleFactor);

	// for each row
	for (row = 0; row < 4; row++)
	{
		// skip the row we're pivoting on
		if (row == column) continue;
		scaleFactor = -Element(row, pivot);
		AddRows(row, scaleFactor, pivot);
		inverse.AddRows(row, scaleFactor, pivot);
	}

	// and we're done
	return 0;
}
Example #4
0
void IceLiveRange::addSegment(int Start, int End) {
#ifdef USE_SET
  RangeElementType Element(Start, End);
  RangeType::iterator Next = Range.lower_bound(Element);
  assert(Next == Range.upper_bound(Element)); // Element not already present

  // Beginning of code that merges contiguous segments.  TODO: change
  // "if(true)" to "if(false)" to see if this extra optimization code
  // gives any performance gain, or is just destabilizing.
  if (true) {
    RangeType::iterator FirstDelete = Next;
    RangeType::iterator Prev = Next;
    bool hasPrev = (Next != Range.begin());
    bool hasNext = (Next != Range.end());
    if (hasPrev)
      --Prev;
    // See if Element and Next should be joined.
    if (hasNext && End == Next->first) {
      Element.second = Next->second;
      ++Next;
    }
    // See if Prev and Element should be joined.
    if (hasPrev && Prev->second == Start) {
      Element.first = Prev->first;
      FirstDelete = Prev;
    }
    Range.erase(FirstDelete, Next);
  }
  // End of code that merges contiguous segments.

  Range.insert(Next, Element);
#else
  if (Range.empty()) {
    Range.push_back(RangeElementType(Start, End));
    return;
  }
  // Special case for faking in-arg liveness.
  if (End < Range.front().first) {
    assert(Start < 0);
    Range.push_front(RangeElementType(Start, End));
    return;
  }
  int CurrentEnd = Range.back().second;
  assert(Start >= CurrentEnd);
  // Check for merge opportunity.
  if (Start == CurrentEnd) {
    Range.back().second = End;
    return;
  }
  Range.push_back(RangeElementType(Start, End));
#endif
}
void SparseMatrix::set_element_at(int i, int j, double n){
    Element temp = Element(j,n);
    bool exist = false;
    DListNode<Element> *trav = row(i).getFirst();
    while(trav != NULL && trav != row(i).getAfterLast()){
        if(trav->getElem().col == j){
            exist = true;
            trav->getElemRef()->setVal(n);
        }
        trav = trav->getNext();
    }
    if(!exist) row(i).insertLast(temp);
}
Example #6
0
    void Train(InputType& data, OutputType& target)
    {
      // Reset the training error.
      trainingError = 0;

      for (size_t i = 0; i < index.n_elem; i++)
      {
        net.FeedForward(Element(data, index(i)),
            Element(target, index(i)), error);

        trainingError += net.Error();
        net.FeedBackward(error);

        if (((i + 1) % batchSize) == 0)
          net.ApplyGradients();
      }

      if ((index.n_elem % batchSize) != 0)
        net.ApplyGradients();

      trainingError /= index.n_elem;
    }
already_AddRefed<SVGTransform>
DOMSVGTransformList::IndexedGetter(uint32_t index, bool& found,
                                   ErrorResult& error)
{
  if (IsAnimValList()) {
    Element()->FlushAnimations();
  }
  found = index < LengthNoFlush();
  if (found) {
    return GetItemAt(index);
  }
  return nullptr;
}
Example #8
0
int CUtlVector<T, A>::InsertBefore(int elem, const T& src)
{
    // Can't insert something that's in the list... reallocation may hose us
    assert((Base() == NULL) || (&src < Base()) || (&src >= (Base() + Count())));

    // Can insert at the end
    assert((elem == Count()) || IsValidIndex(elem));

    GrowVector();
    ShiftElementsRight(elem);
    CopyConstruct(&Element(elem), src);
    return elem;
}
Example #9
0
void Write_Node(TreeNode Node)
{
   int i;

   for (i=1; i <= Rank(Node); i++)
      Write_Node(Child(Node, i));

   Write_String(Tree_File, NodeName(Node));
   fprintf(Tree_File,"\n");
   Write_String(Tree_File, SourceLocation(Node));
   fprintf(Tree_File,"\n");
   fprintf(Tree_File,"%1d\n", Element(Tree,Node+2));
}
Example #10
0
TreeNode Decoration(TreeNode T)
{
   int Neg;
   int Value;

   Value = Element(Tree,T+2);
   Neg = Value < 0;

   if (Neg) 
      return -(abs(Value) / 1000);
   else 
      return Value / 1000;
}
Example #11
0
void Decorate(TreeNode T1, TreeNode T2)
{
   int Neg;
   int NewValue;

   Neg = (T2 < 0);
   NewValue = abs(Element(Tree, T1+2)) % 1000 + abs(T2) * 1000;

   if (Neg) 
      Assign(Tree, T1 + 2, -NewValue);
   else 
      Assign(Tree, T1 + 2, NewValue);
}
void CAI_InterestTarget::Add( CAI_InterestTarget_t::CAI_InterestTarget_e type, CBaseEntity *pTarget, const Vector &vecPosition, float flImportance, float flDuration, float flRamp )
{
	int i = AddToTail();
	CAI_InterestTarget_t &target = Element( i );

	target.m_eType = type;
	target.m_hTarget = pTarget;
	target.m_vecPosition = vecPosition;
	target.m_flInterest = flImportance;
	target.m_flStartTime = gpGlobals->curtime;
	target.m_flEndTime = gpGlobals->curtime + flDuration;
	target.m_flRamp = flRamp / flDuration;
}
void DESolver::Rand2Bin(int candidate)
{
	int r1, r2, r3, r4, r5;
	int n;

	SelectSamples(candidate,&r1,&r2,&r3,&r4,&r5);
	n = (int)RandomUniform(0.0,(double)nDim);

	CopyVector(trialSolution,RowVector(population,candidate));
	for (int i=0; i < nDim; i++) 
	{
		if ((RandomUniform(0.0,1.0) < probability) || (i  == (nDim - 1)))
			trialSolution[n] = Element(population,r1,n)
								+ scale * (Element(population,r2,n)
											+ Element(population,r3,n)
											- Element(population,r4,n)
											- Element(population,r5,n));
		n = (n + 1) % nDim;
	}

	return;
}
Example #14
0
void DOMSVGLength::SetValue(float aUserUnitValue, ErrorResult& aRv) {
  if (mIsAnimValItem) {
    aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
    return;
  }

  if (mVal) {
    aRv = mVal->SetBaseValue(aUserUnitValue, mSVGElement, true);
    return;
  }

  // Although the value passed in is in user units, this method does not turn
  // this length into a user unit length. Instead it converts the user unit
  // value to this length's current unit and sets that, leaving this length's
  // unit as it is.

  if (HasOwner()) {
    if (InternalItem().GetValueInUserUnits(Element(), Axis()) ==
        aUserUnitValue) {
      return;
    }
    float uuPerUnit = InternalItem().GetUserUnitsPerUnit(Element(), Axis());
    if (uuPerUnit > 0) {
      float newValue = aUserUnitValue / uuPerUnit;
      if (IsFinite(newValue)) {
        AutoChangeLengthNotifier notifier(this);
        InternalItem().SetValueAndUnit(newValue, InternalItem().GetUnit());
        return;
      }
    }
  } else if (mUnit == SVGLength_Binding::SVG_LENGTHTYPE_NUMBER ||
             mUnit == SVGLength_Binding::SVG_LENGTHTYPE_PX) {
    mValue = aUserUnitValue;
    return;
  }
  // else [SVGWG issue] Can't convert user unit value to this length's unit
  // ReportToConsole
  aRv.Throw(NS_ERROR_FAILURE);
}
Example #15
0
uint16_t DOMSVGLength::UnitType() {
  if (mVal) {
    if (mIsAnimValItem) {
      mSVGElement->FlushAnimations();
    }
    return mVal->mSpecifiedUnitType;
  }

  if (mIsAnimValItem && HasOwner()) {
    Element()->FlushAnimations();  // May make HasOwner() == false
  }
  return HasOwner() ? InternalItem().GetUnit() : mUnit;
}
Example #16
0
Element ByteGroup::Inverse(const Element &a) const
{
    const QByteArray ba = GetByteArray(a);

    QByteArray out(ba.count(), 0);

    const int c = ba.count();
    for(int i=0; i<c; i++) {
        out[i] = !ba[i];
    }

    return Element(new ByteElementData(out));
}
Example #17
0
xlw::XlfOper4& xlw::XlfOper4::Set(const MyMatrix& values)
{
    if (values.size1() ==0 || values.size2() ==0)
    {
        return *this;
    }

    CellMatrix tmp(values.size1(), values.size2());
    for (unsigned long i=0; i < values.size1(); i++)
        for (unsigned long j=0; j < values.size2(); j++)
            tmp(i,j) = Element(values,i,j);
    return Set(tmp);
}
already_AddRefed<nsISVGPoint>
DOMSVGPointList::IndexedGetter(uint32_t aIndex, bool& aFound,
                               ErrorResult& aError)
{
  if (IsAnimValList()) {
    Element()->FlushAnimations();
  }
  aFound = aIndex < LengthNoFlush();
  if (aFound) {
    return GetItemAt(aIndex);
  }
  return nullptr;
}
Example #19
0
already_AddRefed<nsISVGPoint>
DOMSVGPointList::ReplaceItem(nsISVGPoint& aNewItem, uint32_t aIndex,
                             ErrorResult& aError)
{
  if (IsAnimValList()) {
    aError.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
    return nullptr;
  }

  if (aIndex >= LengthNoFlush()) {
    aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
    return nullptr;
  }

  nsCOMPtr<nsISVGPoint> domItem = &aNewItem;
  if (domItem->HasOwner() || domItem->IsReadonly()) {
    domItem = domItem->Clone(); // must do this before changing anything!
  }

  nsAttrValue emptyOrOldValue = Element()->WillChangePointList();
  if (mItems[aIndex]) {
    // Notify any existing DOM item of removal *before* modifying the lists so
    // that the DOM item can copy the *old* value at its index:
    mItems[aIndex]->RemovingFromList();
  }

  InternalList()[aIndex] = domItem->ToSVGPoint();
  mItems[aIndex] = domItem;

  // This MUST come after the ToSVGPoint() call, otherwise that call
  // would end up reading bad data from InternalList()!
  domItem->InsertingIntoList(this, aIndex, IsAnimValList());

  Element()->DidChangePointList(emptyOrOldValue);
  if (AttrIsAnimating()) {
    Element()->AnimationNeedsResample();
  }
  return domItem.forget();
}
NS_IMETHODIMP
DOMSVGLengthList::Clear()
{
  if (IsAnimValList()) {
    return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
  }

  if (Length() > 0) {
    // Notify any existing DOM items of removal *before* truncating the lists
    // so that they can find their SVGLength internal counterparts and copy
    // their values. This also notifies the animVal list:
    mAList->InternalBaseValListWillChangeTo(SVGLengthList());

    mItems.Clear();
    InternalList().Clear();
    Element()->DidChangeLengthList(AttrEnum(), true);
    if (mAList->IsAnimating()) {
      Element()->AnimationNeedsResample();
    }
  }
  return NS_OK;
}
Example #21
0
void RecipeMLImporter::readRecipemlSrcItems( const QDomElement& sources )
{
    QDomNodeList l = sources.childNodes();
    for ( int i = 0 ; i < l.count(); i++ ) {
        QDomElement srcitem = l.item( i ).toElement();
        QString tagName = srcitem.tagName();

        if ( tagName == "srcitem" )
            recipe.authorList.append( Element( srcitem.text().trimmed() ) );
        else
            kDebug() << "Unknown tag within <source>: " << tagName ;
    }
}
Example #22
0
bool MgWmsLayerDefinitions::GetElementContents(CPSZ pszElementName,STRING& sValue)
{
    MgXmlSynchronizeOnElement Element(*m_xmlParser,pszElementName);
    if(!Element.AtBegin())
        return false;

    if(m_xmlParser->Current().Type() == keText) {
        sValue = m_xmlParser->Current().Contents();
        return true;
    }

    return false;
}
NS_IMETHODIMP
DOMSVGNumberList::RemoveItem(PRUint32 index,
                             nsIDOMSVGNumber **_retval)
{
  *_retval = nsnull;
  if (IsAnimValList()) {
    return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
  }

  if (index >= Length()) {
    return NS_ERROR_DOM_INDEX_SIZE_ERR;
  }

  // Now that we know we're removing, keep animVal list in sync as necessary.
  // Do this *before* touching InternalList() so the removed item can get its
  // internal value.
  MaybeRemoveItemFromAnimValListAt(index);

  // We have to return the removed item, so make sure it exists:
  EnsureItemAt(index);

  // Notify the DOM item of removal *before* modifying the lists so that the
  // DOM item can copy its *old* value:
  mItems[index]->RemovingFromList();
  NS_ADDREF(*_retval = mItems[index]);

  InternalList().RemoveItem(index);
  mItems.RemoveElementAt(index);

  UpdateListIndicesFromIndex(mItems, index);

  Element()->DidChangeNumberList(AttrEnum(), PR_TRUE);
#ifdef MOZ_SMIL
  if (mAList->IsAnimating()) {
    Element()->AnimationNeedsResample();
  }
#endif
  return NS_OK;
}
Example #24
0
NS_IMETHODIMP
DOMSVGLengthList::ReplaceItem(nsIDOMSVGLength *newItem,
                              PRUint32 index,
                              nsIDOMSVGLength **_retval)
{
  *_retval = nsnull;
  if (IsAnimValList()) {
    return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
  }

  nsCOMPtr<DOMSVGLength> domItem = do_QueryInterface(newItem);
  if (!domItem) {
    return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
  }
  if (index >= Length()) {
    return NS_ERROR_DOM_INDEX_SIZE_ERR;
  }
  SVGLength length = domItem->ToSVGLength(); // get before setting domItem
  if (domItem->HasOwner()) {
    domItem = new DOMSVGLength();
  }
  if (mItems[index]) {
    // Notify any existing DOM item of removal *before* modifying the lists so
    // that the DOM item can copy the *old* value at its index:
    mItems[index]->RemovingFromList();
  }
  InternalList()[index] = length;
  domItem->InsertingIntoList(this, AttrEnum(), index, IsAnimValList());
  mItems[index] = domItem;

  Element()->DidChangeLengthList(AttrEnum(), PR_TRUE);
#ifdef MOZ_SMIL
  if (mAList->IsAnimating()) {
    Element()->AnimationNeedsResample();
  }
#endif
  NS_ADDREF(*_retval = domItem.get());
  return NS_OK;
}
Example #25
0
ezQtPropertyContainerWidget::Element& ezQtPropertyContainerWidget::AddElement(ezUInt32 index)
{
  ezQtGroupBoxBase* pSubGroup = CreateElement(m_pGroup);
  pSubGroup->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
  connect(pSubGroup, &ezQtGroupBoxBase::CollapseStateChanged, m_pGrid, &ezQtPropertyGridWidget::OnCollapseStateChanged);
  connect(pSubGroup, &QWidget::customContextMenuRequested, this, &ezQtPropertyContainerWidget::OnCustomElementContextMenu);

  QVBoxLayout* pSubLayout = new QVBoxLayout(nullptr);
  pSubLayout->setContentsMargins(5, 0, 0, 0);
  pSubLayout->setSpacing(1);
  pSubGroup->GetContent()->setLayout(pSubLayout);

  m_pGroupLayout->insertWidget((int)index, pSubGroup);

  ezQtPropertyWidget* pNewWidget = CreateWidget(index);

  pNewWidget->setParent(pSubGroup);
  pSubLayout->addWidget(pNewWidget);

  pNewWidget->Init(m_pGrid, m_pObjectAccessor, m_pType, m_pProp);

  {
    // Add Buttons
    auto pAttr = m_pProp->GetAttributeByType<ezContainerAttribute>();
    if ((!pAttr || pAttr->CanMove()) && m_pProp->GetCategory() != ezPropertyCategory::Map)
    {
      // Do we need move buttons at all if we have drag&drop?
      // ezQtElementGroupButton* pUpButton = new ezQtElementGroupButton(pSubGroup->GetHeader(),
      // ezQtElementGroupButton::ElementAction::MoveElementUp, pNewWidget);  pSubGroup->GetHeader()->layout()->addWidget(pUpButton);
      // connect(pUpButton, &QToolButton::clicked, this, &ezQtPropertyContainerWidget::OnElementButtonClicked);

      // ezQtElementGroupButton* pDownButton = new ezQtElementGroupButton(pSubGroup->GetHeader(),
      // ezQtElementGroupButton::ElementAction::MoveElementDown, pNewWidget);  pSubGroup->GetHeader()->layout()->addWidget(pDownButton);
      // connect(pDownButton, &QToolButton::clicked, this, &ezQtPropertyContainerWidget::OnElementButtonClicked);

      pSubGroup->SetDraggable(true);
      connect(pSubGroup, &ezQtGroupBoxBase::DragStarted, this, &ezQtPropertyContainerWidget::OnDragStarted);
    }

    if (!pAttr || pAttr->CanDelete())
    {
      ezQtElementGroupButton* pDeleteButton =
          new ezQtElementGroupButton(pSubGroup->GetHeader(), ezQtElementGroupButton::ElementAction::DeleteElement, pNewWidget);
      pSubGroup->GetHeader()->layout()->addWidget(pDeleteButton);
      connect(pDeleteButton, &QToolButton::clicked, this, &ezQtPropertyContainerWidget::OnElementButtonClicked);
    }
  }

  m_Elements.Insert(Element(pSubGroup, pNewWidget), index);
  return m_Elements[index];
}
Example #26
0
already_AddRefed<nsISVGPoint>
DOMSVGPointList::RemoveItem(uint32_t aIndex, ErrorResult& aError)
{
  if (IsAnimValList()) {
    aError.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
    return nullptr;
  }

  if (aIndex >= LengthNoFlush()) {
    aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
    return nullptr;
  }

  nsAttrValue emptyOrOldValue = Element()->WillChangePointList();
  // Now that we know we're removing, keep animVal list in sync as necessary.
  // Do this *before* touching InternalList() so the removed item can get its
  // internal value.
  MaybeRemoveItemFromAnimValListAt(aIndex);

  // We have to return the removed item, so make sure it exists:
  EnsureItemAt(aIndex);

  // Notify the DOM item of removal *before* modifying the lists so that the
  // DOM item can copy its *old* value:
  mItems[aIndex]->RemovingFromList();
  nsCOMPtr<nsISVGPoint> result = mItems[aIndex];

  InternalList().RemoveItem(aIndex);
  mItems.RemoveElementAt(aIndex);

  UpdateListIndicesFromIndex(mItems, aIndex);

  Element()->DidChangePointList(emptyOrOldValue);
  if (AttrIsAnimating()) {
    Element()->AnimationNeedsResample();
  }
  return result.forget();
}
Example #27
0
NS_IMETHODIMP
DOMSVGPointList::RemoveItem(PRUint32 aIndex,
                            nsIDOMSVGPoint **_retval)
{
  *_retval = nsnull;
  if (IsAnimValList()) {
    return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
  }

  if (aIndex >= Length()) {
    return NS_ERROR_DOM_INDEX_SIZE_ERR;
  }

  nsAttrValue emptyOrOldValue = Element()->WillChangePointList();
  // Now that we know we're removing, keep animVal list in sync as necessary.
  // Do this *before* touching InternalList() so the removed item can get its
  // internal value.
  MaybeRemoveItemFromAnimValListAt(aIndex);

  // We have to return the removed item, so make sure it exists:
  EnsureItemAt(aIndex);

  // Notify the DOM item of removal *before* modifying the lists so that the
  // DOM item can copy its *old* value:
  mItems[aIndex]->RemovingFromList();
  NS_ADDREF(*_retval = mItems[aIndex]);

  InternalList().RemoveItem(aIndex);
  mItems.RemoveElementAt(aIndex);

  UpdateListIndicesFromIndex(mItems, aIndex);

  Element()->DidChangePointList(emptyOrOldValue);
  if (AttrIsAnimating()) {
    Element()->AnimationNeedsResample();
  }
  return NS_OK;
}
Example #28
0
 /// \brief Inserts 'NewPath' into this trie. \c ConsumedLength denotes
 /// the number of \c NewPath's trailing characters already consumed during
 /// recursion.
 ///
 /// An insert of a path
 /// 'p'starts at the root node and does the following:
 /// - If the node is empty, insert 'p' into its storage and abort.
 /// - If the node has a path 'p2' but no children, take the last path segment
 ///   's' of 'p2', put a new child into the map at 's' an insert the rest of
 ///   'p2' there.
 /// - Insert a new child for the last segment of 'p' and insert the rest of
 ///   'p' there.
 ///
 /// An insert operation is linear in the number of a path's segments.
 void insert(StringRef NewPath, unsigned ConsumedLength = 0) {
   // We cannot put relative paths into the FileMatchTrie as then a path can be
   // a postfix of another path, violating a core assumption of the trie.
   if (llvm::sys::path::is_relative(NewPath))
     return;
   if (Path.empty()) {
     // This is an empty leaf. Store NewPath and return.
     Path = NewPath;
     return;
   }
   if (Children.empty()) {
     // This is a leaf, ignore duplicate entry if 'Path' equals 'NewPath'.
     if (NewPath == Path)
         return;
     // Make this a node and create a child-leaf with 'Path'.
     StringRef Element(llvm::sys::path::filename(
         StringRef(Path).drop_back(ConsumedLength)));
     Children[Element].Path = Path;
   }
   StringRef Element(llvm::sys::path::filename(
         StringRef(NewPath).drop_back(ConsumedLength)));
   Children[Element].insert(NewPath, ConsumedLength + Element.size() + 1);
 }
Example #29
0
nsISVGPoint*
DOMSVGPointList::IndexedGetter(uint32_t aIndex, bool& aFound,
                               ErrorResult& aError)
{
  if (IsAnimValList()) {
    Element()->FlushAnimations();
  }
  aFound = aIndex < LengthNoFlush();
  if (aFound) {
    EnsureItemAt(aIndex);
    return mItems[aIndex];
  }
  return nullptr;
}
Example #30
0
/**
 * @brief MyArray::printSubarrayWithSumClose0
 *Given an array contains positive and negative values,
 *find the subarray, whose sum is most closed to zero. Require nlogn time complexity
 * @param arr
 */
void MyArray::printSubarrayWithSumClose0(vector<int> arr)
{
    if (arr.empty()) return;

    vector<Element> sumArray;
    sumArray.push_back(Element(-1, 0));

    int prev=0;
    for (int i=0; i<arr.size(); i++)
    {
        int sum=arr[i]+prev;
        sumArray.push_back(Element(i, sum));
        prev=sum;
    }
    int start=0, last=0;
    printSubArrayWithSumClose0_sub(sumArray, start, last);
    cout << "SubArray is from " << start+1 << " to " << last << endl;
    for (int i=start+1; i<=last; i++)
        cout << arr[i] << " ";
    cout << endl;


}