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();
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>
567 template <
typename TYPE,
typename ALLOC>
572 template <
typename TYPE,
typename ALLOC>
576 if (this->
size() == 0)
581 auto end = this->findNode(this->
size() - 1);
588 template <
typename TYPE,
typename ALLOC>
592 if (this->
size() == 0)
597 auto end = this->findNode(this->
size() - 1);
604 template <
typename TYPE,
typename ALLOC>
606 if (
this == &
other)
return *
this;
607 this->chainDestroy();
608 this->size_ =
other.size_;
609 if (this->size() != 0){
611 this->begin_ = this->createNode(
other_->getVal());
612 auto this_ = this->begin_;
613 while (
other_->getPNext() !=
nullptr){
615 forwardChainNode::connect(
this_, this->createNode(
other_->getVal()));
621 if constexpr (ALLOC::propagate_on_container_copy_assignment::value){
623 this->rebind_alloc =
other.rebind_alloc;
628 template <
typename TYPE,
typename ALLOC>
630 this->operator=(std::move(
other));
633 template <
typename TYPE,
typename ALLOC>
638 this->chainDestroy();
639 this->begin_ =
other.begin_;
640 this->size_ =
other.size_;
641 if constexpr (ALLOC::propagate_on_container_move_assignment::value){
643 this->rebind_alloc = std::move(
other.rebind_alloc);
649 template <
typename TYPE,
typename ALLOC>
655 template <
typename TYPE,
typename ALLOC>
657 if (this->indexOutOfBound(index)){
660 auto cur = this->findNode(this->parseNegIndex(index));
661 return cur->getVal();
664 template <
typename TYPE,
typename ALLOC>
666 if (this->indexOutOfBound(index)){
669 auto cur = this->findNode(this->parseNegIndex(index));
670 return cur->getVal();
673 template <
typename TYPE,
typename ALLOC>
675 if (this->indexOutOfBound(index)){
678 auto cur = this->findNode(this->parseNegIndex(index));
682 template <
typename TYPE,
typename ALLOC>
694 template <
typename TYPE,
typename ALLOC>
697 if (this->size() == 0){
700 auto next = this->beginNode();
701 forwardChainNode::connect(this->begin_,
new_node);
702 forwardChainNode::connect(
new_node, next);
707 template <
typename TYPE,
typename ALLOC>
709 index = this->parseNegIndex(index);
712 }
else if (index == this->size()){
715 if (this->indexOutOfBound(index)){
719 auto prev = this->findNode(index - 1);
720 auto cur = prev->getPNext();
721 forwardChainNode::connect(prev,
new_node);
727 template <
typename TYPE,
typename ALLOC>
730 if (this->size() == 0){
733 auto end = this->findNode(this->size() - 1);
734 forwardChainNode::connect(end,
new_node);
739 template <
typename TYPE,
typename ALLOC>
742 if (this->size() == 0){
746 res = this->beginNode()->getVal();
747 if (this->size() == 1){
748 this->destroyNode(this->lastDelete());
750 auto del = this->beginNode();
752 this->destroyNode(
del);
753 forwardChainNode::connect(this->begin_,
new_begin);
759 template <
typename TYPE,
typename ALLOC>
761 index = this->parseNegIndex(index);
763 return this->popBegin();
765 if (index == this->size() - 1){
766 return this->popEnd();
768 if (this->indexOutOfBound(index)){
772 auto prev = this->findNode(index - 1);
773 auto cur = prev->getPNext();
775 auto next =
cur->getPNext();
776 forwardChainNode::connect(prev, next);
777 this->destroyNode(
cur);
782 template <
typename TYPE,
typename ALLOC>
785 if (this->size() == 0){
788 if (this->size() == 1){
789 res = this->beginNode()->getVal();
790 this->destroyNode(this->lastDelete());
792 auto new_end = this->findNode(this->size() - 2);
793 auto end =
new_end->getPNext();
795 this->destroyNode(end);
796 forwardChainNode::connect(
new_end,
nullptr);
802 template <
typename TYPE,
typename ALLOC>
804 return new Iterator(this->beginNode());
807 template <
typename TYPE,
typename ALLOC>
809 return new Iterator(this->findNode(this->size() - 1));
812 template <
typename TYPE,
typename ALLOC>
814 return "forwardChain";
817 template <
typename TYPE,
typename ALLOC>
819 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:813
void pushBegin(const TYPE &e) override
Inserts element at the beginning of the chain.
Definition forwardChain.h:695
void pushEnd(const TYPE &e) override
Inserts element at the end of the chain.
Definition forwardChain.h:728
void push(integer index, const TYPE &e) override
Pushes an element at the specified index in the forwardChain.
Definition forwardChain.h:708
TYPE & operator[](integer index) override
Gets a reference to the element at the specified index.
Definition forwardChain.h:665
TYPE popBegin() override
Removes and returns the first element.
Definition forwardChain.h:740
void set(integer index, const TYPE &e) override
Sets the element at the specified index.
Definition forwardChain.h:674
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:808
~forwardChain() override
Destructor for the forwardChain.
Definition forwardChain.h:818
u_integer indexOf(const TYPE &e) const override
Finds the index of the first occurrence of the specified element.
Definition forwardChain.h:683
TYPE pop(integer index) override
Pops an element at the specified index in the forwardChain.
Definition forwardChain.h:760
TYPE popEnd() override
Removes and returns the last element.
Definition forwardChain.h:783
Iterator * begins() const override
Gets an iterator to the beginning of the forwardChain.
Definition forwardChain.h:803
forwardChain & operator=(const forwardChain &other)
Assignment operator for forwardChain.
Definition forwardChain.h:605
TYPE get(integer index) const override
Gets the element at the specified index.
Definition forwardChain.h:656
u_integer size() const override
Gets the size of the forwardChain.
Definition forwardChain.h:650
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
std::uint32_t u_integer
32-bit unsigned integer type for sizes and indexes
Definition config.h:263
std::int64_t integer
64-bit signed integer type for arithmetic operations
Definition config.h:254
Main namespace for the project Original.
Definition algorithms.h:21
SERIAL< TYPE > list(coroutine::generator< TYPE > gen)
Collects generator elements into a list container.
Standard namespace extensions for original::alternative.
Definition allocator.h:351
Single-direction iterator base class.