Macaulay2 Engine
Loading...
Searching...
No Matches

◆ add_vec_to()

void Ring::add_vec_to ( vec & v,
vec & w ) const

Definition at line 550 of file ring-vecs.cpp.

551{
552 if (w == nullptr) return;
553 if (v == nullptr)
554 {
555 v = w;
556 w = nullptr;
557 return;
558 }
559 vecterm head;
560 vec result = &head;
561 while (true)
562 if (v->comp < w->comp)
563 {
564 result->next = w;
565 result = result->next;
566 w = w->next;
567 if (w == nullptr)
568 {
569 result->next = v;
570 v = head.next;
571 return;
572 }
573 }
574 else if (v->comp > w->comp)
575 {
576 result->next = v;
577 result = result->next;
578 v = v->next;
579 if (v == nullptr)
580 {
581 result->next = w;
582 v = head.next;
583 w = nullptr;
584 return;
585 }
586 }
587 else
588 {
589 vec tmv = v;
590 vec tmw = w;
591 v = v->next;
592 w = w->next;
593 tmv->coeff = this->add(tmv->coeff, tmw->coeff);
594 if (this->is_zero(tmv->coeff))
595 {
596 remove_vec_node(tmv);
597 }
598 else
599 {
600 result->next = tmv;
601 result = result->next;
602 }
603 remove_vec_node(tmw);
604 if (w == nullptr)
605 {
606 result->next = v;
607 v = head.next;
608 return;
609 }
610 if (v == nullptr)
611 {
612 result->next = w;
613 v = head.next;
614 w = nullptr;
615 return;
616 }
617 }
618}
void remove_vec_node(vec n) const
Definition ring-vecs.cpp:55
virtual ring_elem add(const ring_elem f, const ring_elem g) const =0
virtual bool is_zero(const ring_elem f) const =0
VALGRIND_MAKE_MEM_DEFINED & result(result)

References add(), is_zero(), vec::next, remove_vec_node(), and result().

Referenced by add_vec(), mult_vec_matrix(), subtract_vec(), subtract_vec_to(), F4toM2Interface::to_M2_vec(), ResF4toM2Interface::to_M2_vec(), and vec_sort().