// File: /workspace/github_cpp_makefile_star2_O1/ruankotovich[P]TextCorrection-Trie/src/trie.hpp
// Function: trie::Trie_t::buildNewSet(std::set<trie::ActiveNode_t, std::less<trie::ActiveNode_t>, std::allocator<trie::ActiveNode_t>>&, unsigned int)
std::set<ActiveNode_t> buildNewSet(std::set<ActiveNode_t>& set, unsigned int curChar)
    {
      std::set<ActiveNode_t> activeNodeSet;

      /*
      ** Considering node N
      ** We can transform the content of this node for the currentWord by first adding a character. (Prebuilt Addiction)
      */
      // std::cout << "\nBuilding node for " << m_reverseCharacterMap[curChar] << '\n';
      for (auto curActiveNode = set.begin(); curActiveNode != set.end(); curActiveNode++) {
        if (curActiveNode->editDistance < m_fuzzyLimitThreshold) {
          // std::cout << " * Updating distance for node " << m_reverseCharacterMap[curActiveNode->node->getContent()] << " from " << curActiveNode->editDistance << " to " << curActiveNode->editDistance + 1 << '\n';
          activeNodeSet.emplace(curActiveNode->node, curActiveNode->editDistance + 1);
        }
      }

      /*
      ** Considering no+de P (child of N)
      ** -  C1. Different character from `curChar` : (Posbuilt Substitution Addiction)
      **    We can transform this character of P for the current character by substitution, relative to ED(N), then, we have to add P to
      **    the set if and only if ED(N)+1 [previously calculated and updated] < threshold
      **
      ** -  C2. Equals character from `curChar` : (Posbuilt Match Addiction)
      **    If this node character match with `curChar`, it means that we got to add it with ED(N) (indeed, when we got a match, we have ED=0) [1]
      **    Once doing it, we have to add the descendant nodes of P (called here `PChild`) with distance PChild = ED(P) + DeepthFrom(P, PChild) < threshold
      **
      ** Addendum [1] - I must update the distance only if the new distance is lower than the last distance (it happens when a previously father node have been calculated)
      */

      for (auto curActiveNode = set.begin(); curActiveNode != set.end(); curActiveNode++) {

        // std::cout << "\nScanning children of node " << m_reverseCharacterMap[curActiveNode->node->getContent()] << '\n';

        for (auto childOfcurActiveNode : curActiveNode->node->getChildren()) {
          // std::cout << " * Node " << m_reverseCharacterMap[childOfcurActiveNode->getContent()] << " found ";
          if (childOfcurActiveNode->getContent() != curChar) { // case 1
            // std::cout << " and haven't matched with the character,";
            if (curActiveNode->editDistance < m_fuzzyLimitThreshold) { // verify if ED(N)+1 < P
              // std::cout << " but it's edit distance can be increased and it would be added to the set";
              int newEditDistance = curActiveNode->editDistance + 1; // the new edit distance for the child

              // retrieves to add the child, return FALSE if it was not possible, cuz the child was already added before (so, i've to verify which edit distance is lower : the current or the previous?)
              auto childIteratorOnSet = activeNodeSet.emplace(childOfcurActiveNode, newEditDistance);

              // if the child was not added (it was cuz' there was a activeNode marked on this node before) and the last ED is bigger than the new ED
              if (!childIteratorOnSet.second) {
                if (childIteratorOnSet.first->editDistance > newEditDistance) {
                  childIteratorOnSet.first->editDistance = newEditDistance; // guaranteed by addendum 1
                }
              }
            }
            // std::cout << '\n';
          } else { // case 2
            // std::cout << " and it matches with the character, so will be added to the set\n";
            // retrieves to add the child, return FALSE if it was not possible, cuz the child was already added before (so, i've to verify which edit distance is lower : the current or the previous?)
            auto childIteratorOnSet = activeNodeSet.emplace(childOfcurActiveNode, curActiveNode->editDistance);

            int currentChildDistance = childIteratorOnSet.first->editDistance;

            if (!childIteratorOnSet.second) { /* processor thanks! */
              if (childIteratorOnSet.first->editDistance > curActiveNode->editDistance) {
                currentChildDistance = childIteratorOnSet.first->editDistance = curActiveNode->editDistance;
              }
            }

            /*
            **  I've to fetch the children and the entire set of children to the active node if
            **  and only if the dist( father, getChildRecursive(father)) ) < threshold;
            */
            // std::cout << "\t\tIt's children will be verifieds to be added to the set : \n";

            std::queue<TrieNode_t*> toRecover; // a queue to save which node is on the way
            toRecover.push(childIteratorOnSet.first->node); // adding the current matched node to the queue

            // while the distance is lesser than the limit and we got some node to recover...
            while (currentChildDistance < m_fuzzyLimitThreshold && !toRecover.empty()) {
              // recover the current node from the queue
              TrieNode_t*& currentNode = toRecover.front();
              // std::cout << "\t\tCurrent node : " << m_reverseCharacterMap[currentNode->getContent()] << '\n';
              // and update the distance to one more
              ++currentChildDistance;

              // for each child of the current node
              for (auto child : currentNode->getChildren()) {

                // we add this child to the active node set, once we can face it as a addiction operation inside the boundary imposed by the search
                auto currentChildIterator = activeNodeSet.emplace(child, currentChildDistance);
                // std::cout << "\t\t * Children " << m_reverseCharacterMap[currentChildIterator.first->node->getContent()] << " added to the set ";
                // if there was this child within the activeNode, we have to keep the minor operation distance
                if (!currentChildIterator.second) {
                  // std::cout << "by update/permanence ";
                  if (currentChildIterator.first->editDistance > currentChildDistance) {
                    currentChildIterator.first->editDistance = currentChildDistance;
                  }
                }
                // std::cout<<" with edit distance " << currentChildIterator.first->editDistance << '\n';

                // and put it if and only if the currentDistance is lesser than the thresould (the memory and processment thank!)
                if (currentChildDistance < m_fuzzyLimitThreshold) {
                  toRecover.push(child);
                }
              }
              toRecover.pop();
            }
          }
        }
      }
      // std::cout << "\n\n";
      return activeNodeSet;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %ecx, 0xc(%rsp)
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x8(%rdi), %rax
movl $0x0, 0x8(%rdi)
xorl %ecx, %ecx
movq %rcx, 0x10(%rdi)
movq %rax, 0x18(%rdi)
movq %rax, 0x20(%rdi)
movq %rcx, 0x28(%rdi)
movq 0x18(%rdx), %r12
leaq 0x8(%rdx), %rbp
cmpq %rbp, %r12
je 0x5eaf
leaq 0x10(%rsp), %r13
movl 0x28(%r12), %eax
cmpl 0xdc(%r14), %eax
jge 0x5e9f
leaq 0x20(%r12), %rsi
incl %eax
movl %eax, 0x10(%rsp)
movq %rbx, %rdi
movq %r13, %rdx
callq 0x63a2
movq %r12, %rdi
callq 0x21b0
movq %rax, %r12
cmpq %rbp, %rax
jne 0x5e7b
movq 0x18(%r15), %r12
movq %rbp, 0xa8(%rsp)
cmpq %rbp, %r12
je 0x6189
leaq 0x68(%rsp), %r15
leaq 0x8(%rsp), %rbp
movq 0x20(%r12), %rsi
leaq 0x90(%rsp), %rdi
callq 0x4ed8
movq 0x90(%rsp), %rax
movq 0x98(%rsp), %rcx
movq %rcx, 0xb0(%rsp)
cmpq %rcx, %rax
je 0x6153
leaq 0x28(%r12), %rcx
movq %rcx, 0x60(%rsp)
movq %r12, 0xc0(%rsp)
movq %rax, 0xb8(%rsp)
movq (%rax), %rax
movq %rax, 0x70(%rsp)
movl 0xc(%rsp), %ecx
cmpl %ecx, 0x30(%rax)
jne 0x5fb2
movq %rbx, %rdi
leaq 0x70(%rsp), %rsi
movq 0x60(%rsp), %rdx
callq 0x5b60
movq %rax, %r13
movl 0x28(%rax), %eax
movl %eax, 0x8(%rsp)
testb $0x1, %dl
jne 0x5f64
movq 0x60(%rsp), %rcx
movl (%rcx), %ecx
cmpl %ecx, %eax
jle 0x5f64
movl %ecx, 0x28(%r13)
movl %ecx, 0x8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x6450
addq $0x20, %r13
movq 0x40(%rsp), %rax
movq 0x50(%rsp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
je 0x5ffa
movq (%r13), %rcx
movq %rcx, (%rax)
addq $0x8, 0x40(%rsp)
jmp 0x6007
movl 0x28(%r12), %eax
cmpl 0xdc(%r14), %eax
jge 0x6139
incl %eax
movl %eax, 0x10(%rsp)
movq %rbx, %rdi
leaq 0x70(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x5b60
testb $0x1, %dl
jne 0x6139
movl 0x10(%rsp), %ecx
cmpl %ecx, 0x28(%rax)
jle 0x6139
movl %ecx, 0x28(%rax)
jmp 0x6139
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x65c6
movl 0x8(%rsp), %eax
cmpl 0xdc(%r14), %eax
jge 0x612f
movq 0x20(%rsp), %rcx
cmpq %rcx, 0x40(%rsp)
je 0x612f
incl %eax
movl %eax, 0x8(%rsp)
movq (%rcx), %rsi
leaq 0x78(%rsp), %rdi
callq 0x4ed8
movq 0x78(%rsp), %r13
movq 0x80(%rsp), %r12
cmpq %r12, %r13
je 0x60b8
movq (%r13), %rax
movq %rax, 0x68(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x5b60
testb $0x1, %dl
jne 0x6075
movl 0x8(%rsp), %ecx
cmpl %ecx, 0x28(%rax)
jle 0x6075
movl %ecx, 0x28(%rax)
movl 0x8(%rsp), %eax
cmpl 0xdc(%r14), %eax
jge 0x60b2
movq 0x40(%rsp), %rax
movq 0x50(%rsp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
je 0x60a5
movq 0x68(%rsp), %rcx
movq %rcx, (%rax)
addq $0x8, 0x40(%rsp)
jmp 0x60b2
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x65c6
addq $0x8, %r13
jmp 0x6048
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x60d2
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x20(%rsp), %rax
movq 0x30(%rsp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
movq 0xc0(%rsp), %r12
je 0x60f3
addq $0x8, %rax
jmp 0x6125
movq 0x28(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x2180
movq 0x38(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x38(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
leaq 0x200(%rax), %rcx
movq %rcx, 0x30(%rsp)
movq %rax, 0x20(%rsp)
jmp 0x6007
leaq 0x10(%rsp), %rdi
callq 0x67da
movq 0xb8(%rsp), %rax
addq $0x8, %rax
cmpq 0xb0(%rsp), %rax
jne 0x5f13
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x6170
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq %r12, %rdi
callq 0x21b0
movq %rax, %r12
cmpq 0xa8(%rsp), %rax
jne 0x5ece
movq %rbx, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x61a0
movq %rax, %r14
jmp 0x61f9
jmp 0x61b0
jmp 0x61ab
jmp 0x61ab
movq %rax, %r14
jmp 0x61dc
movq %rax, %r14
jmp 0x61d2
movq %rax, %r14
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x61d2
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
leaq 0x10(%rsp), %rdi
callq 0x67da
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x61f9
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x47b2
movq %r14, %rdi
callq 0x2270
nop