32 template <
typename TYPE,
typename ALLOC = allocator<TYPE>>
52 explicit forwardChainNode(
const TYPE& data =
TYPE{}, forwardChainNode* next =
nullptr);
55 forwardChainNode* next;
62 forwardChainNode(
const forwardChainNode&
other);
69 forwardChainNode& operator=(
const forwardChainNode&
other);
75 TYPE& getVal()
override;
81 const TYPE& getVal()
const override;
87 void setVal(
TYPE data)
override;
94 forwardChainNode* getPPrev()
const override;
100 forwardChainNode* getPNext()
const override;
106 void setPNext(forwardChainNode*
new_next);
114 static void connect(forwardChainNode* prev, forwardChainNode* next);
125 forwardChainNode* begin_;
126 rebind_alloc_node rebind_alloc{};
133 forwardChainNode* beginNode()
const;
141 forwardChainNode* findNode(
integer index)
const;
151 forwardChainNode* createNode(
const TYPE& value =
TYPE{}, forwardChainNode* next =
nullptr);
159 void destroyNode(forwardChainNode*
node)
noexcept;
172 void firstAdd(forwardChainNode*
node);
179 forwardChainNode* lastDelete();
201 explicit Iterator(forwardChainNode* ptr);
380 Iterator*
begins()
const override;
386 Iterator*
ends()
const override;
401 template <
typename TYPE,
typename ALLOC>
403 : data_(data), next(next) {}
405 template <
typename TYPE,
typename ALLOC>
407 : data_(other.data_), next(other.next) {}
409 template <
typename TYPE,
typename ALLOC>
411 const forwardChainNode &other) -> forwardChainNode & {
412 if (
this != &other) {
419 template <
typename TYPE,
typename ALLOC>
424 template <
typename TYPE,
typename ALLOC>
429 template <
typename TYPE,
typename ALLOC>
434 template <
typename TYPE,
typename ALLOC>
436 throw unSupportedMethodError();
439 template <
typename TYPE,
typename ALLOC>
444 template <
typename TYPE,
typename ALLOC>
446 this->next = new_next;
449 template <
typename TYPE,
typename ALLOC>
451 forwardChainNode *prev, forwardChainNode *next) ->
void {
452 if (prev !=
nullptr) prev->setPNext(next);
455 template <
typename TYPE,
typename ALLOC>
458 return this->begin_->getPNext();
461 template <
typename TYPE,
typename ALLOC>
463 if (this->
size() == 0)
return this->begin_;
464 auto cur = this->beginNode();
465 for(u_integer i = 0; i < index; i++)
467 cur = cur->getPNext();
472 template<
typename TYPE,
typename ALLOC>
474 auto node = this->rebind_alloc.allocate(1);
475 this->rebind_alloc.construct(node, value, next);
479 template<
typename TYPE,
typename ALLOC>
481 this->rebind_alloc.destroy(node);
482 this->rebind_alloc.deallocate(node, 1);
485 template <
typename TYPE,
typename ALLOC>
488 auto pivot = this->createNode();
490 this->begin_ = pivot;
493 template <
typename TYPE,
typename ALLOC>
496 forwardChainNode::connect(this->findNode(0), node);
500 template <
typename TYPE,
typename ALLOC>
503 auto last = this->beginNode();
504 this->destroyNode(this->begin_);
509 template <
typename TYPE,
typename ALLOC>
512 auto cur = this->begin_;
515 auto next = cur->getPNext();
516 this->destroyNode(cur);
521 template <
typename TYPE,
typename ALLOC>
523 : singleDirectionIterator<TYPE>(ptr) {}
525 template <
typename TYPE,
typename ALLOC>
531 template <
typename TYPE,
typename ALLOC>
533 if (
this == &
other)
return *
this;
538 template <
typename TYPE,
typename ALLOC>
543 template <
typename TYPE,
typename ALLOC>
549 template <
typename TYPE,
typename ALLOC>
555 template <
typename TYPE,
typename ALLOC>
557 return "forwardChain::Iterator";
560 template <
typename TYPE,
typename ALLOC>
565 rebind_alloc(
std::
move(rebind_alloc_node{}))
570 template <
typename TYPE,
typename ALLOC>
575 template <
typename TYPE,
typename ALLOC>
579 if (this->
size() == 0)
584 auto end = this->findNode(this->
size() - 1);
591 template <
typename TYPE,
typename ALLOC>
595 if (this->
size() == 0)
600 auto end = this->findNode(this->
size() - 1);
607 template <
typename TYPE,
typename ALLOC>
609 if (
this == &
other)
return *
this;
610 this->chainDestroy();
611 this->size_ =
other.size_;
612 if (this->size() != 0){
614 this->begin_ = this->createNode(
other_->getVal());
615 auto this_ = this->begin_;
616 while (
other_->getPNext() !=
nullptr){
618 forwardChainNode::connect(
this_, this->createNode(
other_->getVal()));
624 if constexpr (ALLOC::propagate_on_container_copy_assignment::value){
626 this->rebind_alloc =
other.rebind_alloc;
631 template <
typename TYPE,
typename ALLOC>
633 this->operator=(std::move(
other));
636 template <
typename TYPE,
typename ALLOC>
641 this->chainDestroy();
642 this->begin_ =
other.begin_;
643 this->size_ =
other.size_;
644 if constexpr (ALLOC::propagate_on_container_move_assignment::value){
646 this->rebind_alloc = std::move(
other.rebind_alloc);
652 template <
typename TYPE,
typename ALLOC>
658 template <
typename TYPE,
typename ALLOC>
660 if (this->indexOutOfBound(index)){
663 auto cur = this->findNode(this->parseNegIndex(index));
664 return cur->getVal();
667 template <
typename TYPE,
typename ALLOC>
669 if (this->indexOutOfBound(index)){
672 auto cur = this->findNode(this->parseNegIndex(index));
673 return cur->getVal();
676 template <
typename TYPE,
typename ALLOC>
678 if (this->indexOutOfBound(index)){
681 auto cur = this->findNode(this->parseNegIndex(index));
685 template <
typename TYPE,
typename ALLOC>
697 template <
typename TYPE,
typename ALLOC>
700 if (this->size() == 0){
703 auto next = this->beginNode();
704 forwardChainNode::connect(this->begin_,
new_node);
705 forwardChainNode::connect(
new_node, next);
710 template <
typename TYPE,
typename ALLOC>
712 index = this->parseNegIndex(index);
715 }
else if (index == this->size()){
718 if (this->indexOutOfBound(index)){
722 auto prev = this->findNode(index - 1);
723 auto cur = prev->getPNext();
724 forwardChainNode::connect(prev,
new_node);
730 template <
typename TYPE,
typename ALLOC>
733 if (this->size() == 0){
736 auto end = this->findNode(this->size() - 1);
737 forwardChainNode::connect(end,
new_node);
742 template <
typename TYPE,
typename ALLOC>
745 if (this->size() == 0){
749 res = this->beginNode()->getVal();
750 if (this->size() == 1){
751 this->destroyNode(this->lastDelete());
753 auto del = this->beginNode();
755 this->destroyNode(
del);
756 forwardChainNode::connect(this->begin_,
new_begin);
762 template <
typename TYPE,
typename ALLOC>
764 index = this->parseNegIndex(index);
766 return this->popBegin();
768 if (index == this->size() - 1){
769 return this->popEnd();
771 if (this->indexOutOfBound(index)){
775 auto prev = this->findNode(index - 1);
776 auto cur = prev->getPNext();
778 auto next =
cur->getPNext();
779 forwardChainNode::connect(prev, next);
780 this->destroyNode(
cur);
785 template <
typename TYPE,
typename ALLOC>
788 if (this->size() == 0){
791 if (this->size() == 1){
792 res = this->beginNode()->getVal();
793 this->destroyNode(this->lastDelete());
795 auto new_end = this->findNode(this->size() - 2);
796 auto end =
new_end->getPNext();
798 this->destroyNode(end);
799 forwardChainNode::connect(
new_end,
nullptr);
805 template <
typename TYPE,
typename ALLOC>
807 return new Iterator(this->beginNode());
810 template <
typename TYPE,
typename ALLOC>
812 return new Iterator(this->findNode(this->size() - 1));
815 template <
typename TYPE,
typename ALLOC>
817 return "forwardChain";
820 template <
typename TYPE,
typename ALLOC>
822 this->chainDestroy();
Provides the array class for a fixed-size container with random access.
Provides a base class for variable-size serial containers.
Default memory allocator using allocators utilities.
Definition allocator.h:153
const TYPE * get() const
Get managed pointer const version.
Definition autoPtr.h:629
Base class for variable-size serial containers.
Definition baseList.h:43
Iterator for forwardChain, supports single-direction traversal.
Definition forwardChain.h:196
bool atPrev(const iterator< TYPE > *other) const override
Checks if this iterator is at the previous element relative to another iterator.
Definition forwardChain.h:544
std::string className() const override
Gets the class name of the iterator.
Definition forwardChain.h:556
Iterator * clone() const override
Clones the iterator.
Definition forwardChain.h:539
Iterator & operator=(const Iterator &other)
Assignment operator for Iterator.
Definition forwardChain.h:532
bool atNext(const iterator< TYPE > *other) const override
Checks if this iterator is at the next element relative to another iterator.
Definition forwardChain.h:550
A singly linked list implementation.
Definition forwardChain.h:33
std::string className() const override
Gets the class name of the forwardChain.
Definition forwardChain.h:816
void pushBegin(const TYPE &e) override
Inserts element at the beginning of the chain.
Definition forwardChain.h:698
void pushEnd(const TYPE &e) override
Inserts element at the end of the chain.
Definition forwardChain.h:731
void push(integer index, const TYPE &e) override
Pushes an element at the specified index in the forwardChain.
Definition forwardChain.h:711
TYPE & operator[](integer index) override
Gets a reference to the element at the specified index.
Definition forwardChain.h:668
TYPE popBegin() override
Removes and returns the first element.
Definition forwardChain.h:743
void set(integer index, const TYPE &e) override
Sets the element at the specified index.
Definition forwardChain.h:677
forwardChain(ALLOC alloc=ALLOC{})
Constructs an empty forwardChain with specified allocator.
Definition forwardChain.h:561
Iterator * ends() const override
Gets an iterator to the end of the forwardChain.
Definition forwardChain.h:811
~forwardChain() override
Destructor for the forwardChain.
Definition forwardChain.h:821
u_integer indexOf(const TYPE &e) const override
Finds the index of the first occurrence of the specified element.
Definition forwardChain.h:686
TYPE pop(integer index) override
Pops an element at the specified index in the forwardChain.
Definition forwardChain.h:763
TYPE popEnd() override
Removes and returns the last element.
Definition forwardChain.h:786
Iterator * begins() const override
Gets an iterator to the beginning of the forwardChain.
Definition forwardChain.h:806
forwardChain & operator=(const forwardChain &other)
Assignment operator for forwardChain.
Definition forwardChain.h:608
TYPE get(integer index) const override
Gets the element at the specified index.
Definition forwardChain.h:659
u_integer size() const override
Gets the size of the forwardChain.
Definition forwardChain.h:653
iterAdaptor end()
Returns an iterator adapter pointing to the end sentinel of the container.
Definition iterable.h:631
iterAdaptor last()
Returns an iterator adapter pointing to the last element.
Definition iterable.h:656
A stream class that allows iteration, comparison, hashing and printing.
Definition iterationStream.h:60
Base iterator interface that supports common operations for iteration.
Definition iterator.h:37
Exception for missing element requests.
Definition error.h:298
Exception for container index out-of-range errors.
Definition error.h:192
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37
Abstract base class for unique element containers.
Definition set.h:44
Abstract base class for single-direction iterators.
Definition singleDirectionIterator.h:25
singleDirectionIterator & operator=(const singleDirectionIterator &other)
Copy assignment operator for singleDirectionIterator.
Definition singleDirectionIterator.h:65
Base class for linked value containers with formatted output.
Definition wrapper.h:28
Main namespace for the project Original.
Definition algorithms.h:21
SERIAL< TYPE > list(coroutine::generator< TYPE > gen)
Collects generator elements into a list container.
Definition generators.h:655
Standard namespace extensions for original::alternative.
Definition allocator.h:351
Single-direction iterator base class.