// File: migueeelvargas[P]Auto-Complete/test.cpp
// Function: modeTrie(DictionaryTrie*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&)
void modeTrie (DictionaryTrie* dictionaryTrie, 
              std::vector<std::string>& words,
              std::vector<std::string>& wordsNotIn) {
    /* Test - insert() */
  std::cout << "Inserting strings..." << std::endl;
  for( auto i = words.begin(); i != words.end(); ++i) {
    // auto freq = (unsigned int)rand()%100;
    auto freq = 10;
    if (dictionaryTrie->insert(*i, freq))
      std::cout << "Inserted " << "\"" << *i << ", " << freq << "\"" << std::endl;

    else {
      std::cout << "\"" << *i << "\"" << " is already in dictionary." << std::endl;
      pass = false;
    }
  }
  if (pass)
    std::cout << "PASSED." << std::endl << std::endl;
  else 
    std::cout << "FAILED." << std::endl << std::endl;

  /* Testing Re-Insert - Should return all false */
  pass = true;
  std::cout << "Re-Inserting strings..." << std::endl;
  for( auto i = words.begin(); i != words.end(); ++i) {
    if (dictionaryTrie->insert(*i, 10)) {
      std::cout << "Inserted " << "\"" << *i << "\"" << std::endl;
      pass = false;
    }

    else 
      std::cout << "\"" << *i << "\"" << " is already in dictionary." << std::endl;
  }
  if (pass)
    std::cout << "PASSED." << std::endl << std::endl;
  else 
    std::cout << "FAILED." << std::endl << std::endl;

  /* Testing - find() */
  pass = true;
  std::cout << "Finding strings..." << std::endl;
  for( auto i = words.begin(); i != words.end(); ++i) {
    if (dictionaryTrie->find(*i))
      std::cout << "Found " << "\"" << *i << "\"" << std::endl;

    else {
      std::cout << "\"" << *i << "\"" << " is not in the dictionary." << std::endl;
      pass = false;
    }
  }
  for( auto i = wordsNotIn.begin(); i != wordsNotIn.end(); ++i) {
    if (dictionaryTrie->find(*i)) {
      std::cout << "Found " << "\"" << *i << "\"" << std::endl;
      pass = false;
    }

    else {
      std::cout << "\"" << *i << "\"" << " is not in the dictionary." << std::endl;
    }
  }
  if (pass)
    std::cout << "PASSED." << std::endl << std::endl;
  else 
    std::cout << "FAILED." << std::endl << std::endl << std::endl;

  /* Print # of vertices */
  std::cout << "# of vertices: " << dictionaryTrie->num_vertices << std::endl << std::endl;

  /* Testing predictCompletions */
  std::cout << "Testing predictCompletions..." << std::endl;
  auto prefix = "b";
  auto num = 4;

  auto completions = dictionaryTrie->predictCompletions(prefix, num);

  if(completions.empty())
    std::cout << std::endl << "The prefix does not have any words in the dictionary." << std::endl;

  else {
    std::cout << "finding the top " << num << " completions for: " << prefix << std::endl;

    for(auto it = completions.begin(); it != completions.end(); ++it) {
      std::cout << *it << std::endl;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq 0xd87a(%rip), %rdi      # 0x10fd8
leaq 0x7978(%rip), %rsi      # 0xb0dd
callq 0x21a0
movq %rax, %rdi
movq 0xd854(%rip), %rsi      # 0x10fc8
callq 0x21e0
movq -0x10(%rbp), %rdi
callq 0x43e0
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4450
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x4410
testb $0x1, %al
jne 0x37a9
jmp 0x391b
movl $0xa, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x4480
movq %rax, %rsi
leaq -0x50(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x20a0
movq -0x168(%rbp), %rdi
movq -0x160(%rbp), %rsi
movl -0x2c(%rbp), %edx
callq 0x80a0
movb %al, -0x151(%rbp)
jmp 0x37f5
leaq -0x50(%rbp), %rdi
callq 0x2100
movb -0x151(%rbp), %al
testb $0x1, %al
jne 0x380d
jmp 0x38a5
movq 0xd7c4(%rip), %rdi      # 0x10fd8
leaq 0x7839(%rip), %rsi      # 0xb054
callq 0x21a0
movq %rax, %rdi
leaq 0x7834(%rip), %rsi      # 0xb05e
callq 0x21a0
movq %rax, -0x170(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x4480
movq -0x170(%rbp), %rdi
movq %rax, %rsi
callq 0x2190
movq %rax, %rdi
leaq 0x787f(%rip), %rsi      # 0xb0d7
callq 0x21a0
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x77ec(%rip), %rsi      # 0xb05e
callq 0x21a0
movq %rax, %rdi
movq 0xd747(%rip), %rsi      # 0x10fc8
callq 0x21e0
jmp 0x390b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x2100
jmp 0x426e
movq 0xd72c(%rip), %rdi      # 0x10fd8
leaq 0x77ab(%rip), %rsi      # 0xb05e
callq 0x21a0
movq %rax, -0x178(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x4480
movq -0x178(%rbp), %rdi
movq %rax, %rsi
callq 0x2190
movq %rax, %rdi
leaq 0x777d(%rip), %rsi      # 0xb05e
callq 0x21a0
movq %rax, %rdi
leaq 0x7770(%rip), %rsi      # 0xb060
callq 0x21a0
movq %rax, %rdi
movq 0xd6c9(%rip), %rsi      # 0x10fc8
callq 0x21e0
movb $0x0, 0xd89d(%rip)      # 0x111a8
jmp 0x390d
leaq -0x20(%rbp), %rdi
callq 0x44a0
jmp 0x3786
testb $0x1, 0xd886(%rip)      # 0x111a8
je 0x3957
movq 0xd6ad(%rip), %rdi      # 0x10fd8
leaq 0x7749(%rip), %rsi      # 0xb07b
callq 0x21a0
movq %rax, %rdi
movq 0xd687(%rip), %rsi      # 0x10fc8
callq 0x21e0
movq %rax, %rdi
movq 0xd678(%rip), %rsi      # 0x10fc8
callq 0x21e0
jmp 0x3988
movq 0xd67a(%rip), %rdi      # 0x10fd8
leaq 0x771e(%rip), %rsi      # 0xb083
callq 0x21a0
movq %rax, %rdi
movq 0xd654(%rip), %rsi      # 0x10fc8
callq 0x21e0
movq %rax, %rdi
movq 0xd645(%rip), %rsi      # 0x10fc8
callq 0x21e0
movb $0x1, 0xd819(%rip)      # 0x111a8
movq 0xd642(%rip), %rdi      # 0x10fd8
leaq 0x773d(%rip), %rsi      # 0xb0da
callq 0x21a0
movq %rax, %rdi
movq 0xd61c(%rip), %rsi      # 0x10fc8
callq 0x21e0
movq -0x10(%rbp), %rdi
callq 0x43e0
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4450
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4410
testb $0x1, %al
jne 0x39e1
jmp 0x3b3a
movq -0x8(%rbp), %rax
movq %rax, -0x190(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x4480
movq %rax, %rsi
leaq -0x90(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x20a0
movq -0x190(%rbp), %rdi
movq -0x188(%rbp), %rsi
movl $0xa, %edx
callq 0x80a0
movb %al, -0x179(%rbp)
jmp 0x3a2b
leaq -0x90(%rbp), %rdi
callq 0x2100
movb -0x179(%rbp), %al
testb $0x1, %al
jne 0x3a46
jmp 0x3acb
movq 0xd58b(%rip), %rdi      # 0x10fd8
leaq 0x7600(%rip), %rsi      # 0xb054
callq 0x21a0
movq %rax, %rdi
leaq 0x75fb(%rip), %rsi      # 0xb05e
callq 0x21a0
movq %rax, -0x198(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x4480
movq -0x198(%rbp), %rdi
movq %rax, %rsi
callq 0x2190
movq %rax, %rdi
leaq 0x75cd(%rip), %rsi      # 0xb05e
callq 0x21a0
movq %rax, %rdi
movq 0xd528(%rip), %rsi      # 0x10fc8
callq 0x21e0
movb $0x0, 0xd6fc(%rip)      # 0x111a8
jmp 0x3b2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x2100
jmp 0x426e
movq 0xd506(%rip), %rdi      # 0x10fd8
leaq 0x7585(%rip), %rsi      # 0xb05e
callq 0x21a0
movq %rax, -0x1a0(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x4480
movq -0x1a0(%rbp), %rdi
movq %rax, %rsi
callq 0x2190
movq %rax, %rdi
leaq 0x7557(%rip), %rsi      # 0xb05e
callq 0x21a0
movq %rax, %rdi
leaq 0x754a(%rip), %rsi      # 0xb060
callq 0x21a0
movq %rax, %rdi
movq 0xd4a3(%rip), %rsi      # 0x10fc8
callq 0x21e0
jmp 0x3b2c
leaq -0x68(%rbp), %rdi
callq 0x44a0
jmp 0x39be
testb $0x1, 0xd667(%rip)      # 0x111a8
je 0x3b76
movq 0xd48e(%rip), %rdi      # 0x10fd8
leaq 0x752a(%rip), %rsi      # 0xb07b
callq 0x21a0
movq %rax, %rdi
movq 0xd468(%rip), %rsi      # 0x10fc8
callq 0x21e0
movq %rax, %rdi
movq 0xd459(%rip), %rsi      # 0x10fc8
callq 0x21e0
jmp 0x3ba7
movq 0xd45b(%rip), %rdi      # 0x10fd8
leaq 0x74ff(%rip), %rsi      # 0xb083
callq 0x21a0
movq %rax, %rdi
movq 0xd435(%rip), %rsi      # 0x10fc8
callq 0x21e0
movq %rax, %rdi
movq 0xd426(%rip), %rsi      # 0x10fc8
callq 0x21e0
movb $0x1, 0xd5fa(%rip)      # 0x111a8
movq 0xd423(%rip), %rdi      # 0x10fd8
leaq 0x74d5(%rip), %rsi      # 0xb091
callq 0x21a0
movq %rax, %rdi
movq 0xd3fd(%rip), %rsi      # 0x10fc8
callq 0x21e0
movq -0x10(%rbp), %rdi
callq 0x43e0
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4450
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x4410
testb $0x1, %al
jne 0x3c0c
jmp 0x3d6f
movq -0x8(%rbp), %rax
movq %rax, -0x1b8(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x4480
movq %rax, %rsi
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x20a0
movq -0x1b8(%rbp), %rdi
movq -0x1b0(%rbp), %rsi
callq 0x85c0
movb %al, -0x1a1(%rbp)
jmp 0x3c54
leaq -0xc0(%rbp), %rdi
callq 0x2100
movb -0x1a1(%rbp), %al
testb $0x1, %al
jne 0x3c6f
jmp 0x3cf3
movq 0xd362(%rip), %rdi      # 0x10fd8
leaq 0x7427(%rip), %rsi      # 0xb0a4
callq 0x21a0
movq %rax, %rdi
leaq 0x73d2(%rip), %rsi      # 0xb05e
callq 0x21a0
movq %rax, -0x1c0(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x4480
movq -0x1c0(%rbp), %rdi
movq %rax, %rsi
callq 0x2190
movq %rax, %rdi
leaq 0x73a1(%rip), %rsi      # 0xb05e
callq 0x21a0
movq %rax, %rdi
movq 0xd2fc(%rip), %rsi      # 0x10fc8
callq 0x21e0
jmp 0x3d5c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x2100
jmp 0x426e
movq 0xd2de(%rip), %rdi      # 0x10fd8
leaq 0x735d(%rip), %rsi      # 0xb05e
callq 0x21a0
movq %rax, -0x1c8(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x4480
movq -0x1c8(%rbp), %rdi
movq %rax, %rsi
callq 0x2190
movq %rax, %rdi
leaq 0x732c(%rip), %rsi      # 0xb05e
callq 0x21a0
movq %rax, %rdi
leaq 0x7371(%rip), %rsi      # 0xb0b2
callq 0x21a0
movq %rax, %rdi
movq 0xd278(%rip), %rsi      # 0x10fc8
callq 0x21e0
movb $0x0, 0xd44c(%rip)      # 0x111a8
jmp 0x3d5e
leaq -0x98(%rbp), %rdi
callq 0x44a0
jmp 0x3be0
movq -0x18(%rbp), %rdi
callq 0x43e0
movq %rax, -0xc8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4450
movq %rax, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x4410
testb $0x1, %al
jne 0x3dab
jmp 0x3f0b
movq -0x8(%rbp), %rax
movq %rax, -0x1e0(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x4480
movq %rax, %rsi
leaq -0xf0(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x20a0
movq -0x1e0(%rbp), %rdi
movq -0x1d8(%rbp), %rsi
callq 0x85c0
movb %al, -0x1c9(%rbp)
jmp 0x3df3
leaq -0xf0(%rbp), %rdi
callq 0x2100
movb -0x1c9(%rbp), %al
testb $0x1, %al
jne 0x3e0e
jmp 0x3e96
movq 0xd1c3(%rip), %rdi      # 0x10fd8
leaq 0x7288(%rip), %rsi      # 0xb0a4
callq 0x21a0
movq %rax, %rdi
leaq 0x7233(%rip), %rsi      # 0xb05e
callq 0x21a0
movq %rax, -0x1e8(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x4480
movq -0x1e8(%rbp), %rdi
movq %rax, %rsi
callq 0x2190
movq %rax, %rdi
leaq 0x7202(%rip), %rsi      # 0xb05e
callq 0x21a0
movq %rax, %rdi
movq 0xd15d(%rip), %rsi      # 0x10fc8
callq 0x21e0
movb $0x0, 0xd331(%rip)      # 0x111a8
jmp 0x3ef8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x2100
jmp 0x426e
movq 0xd13b(%rip), %rdi      # 0x10fd8
leaq 0x71ba(%rip), %rsi      # 0xb05e
callq 0x21a0
movq %rax, -0x1f0(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x4480
movq -0x1f0(%rbp), %rdi
movq %rax, %rsi
callq 0x2190
movq %rax, %rdi
leaq 0x7189(%rip), %rsi      # 0xb05e
callq 0x21a0
movq %rax, %rdi
leaq 0x71ce(%rip), %rsi      # 0xb0b2
callq 0x21a0
movq %rax, %rdi
movq 0xd0d5(%rip), %rsi      # 0x10fc8
callq 0x21e0
jmp 0x3efa
leaq -0xc8(%rbp), %rdi
callq 0x44a0
jmp 0x3d7f
testb $0x1, 0xd296(%rip)      # 0x111a8
je 0x3f47
movq 0xd0bd(%rip), %rdi      # 0x10fd8
leaq 0x7159(%rip), %rsi      # 0xb07b
callq 0x21a0
movq %rax, %rdi
movq 0xd097(%rip), %rsi      # 0x10fc8
callq 0x21e0
movq %rax, %rdi
movq 0xd088(%rip), %rsi      # 0x10fc8
callq 0x21e0
jmp 0x3f87
movq 0xd08a(%rip), %rdi      # 0x10fd8
leaq 0x712e(%rip), %rsi      # 0xb083
callq 0x21a0
movq %rax, %rdi
movq 0xd064(%rip), %rsi      # 0x10fc8
callq 0x21e0
movq %rax, %rdi
movq 0xd055(%rip), %rsi      # 0x10fc8
callq 0x21e0
movq %rax, %rdi
movq 0xd046(%rip), %rsi      # 0x10fc8
callq 0x21e0
movq 0xd04a(%rip), %rdi      # 0x10fd8
movq %rdi, -0x218(%rbp)
leaq 0x7156(%rip), %rsi      # 0xb0f2
callq 0x21a0
movq %rax, %rdi
movq -0x8(%rbp), %rax
movl (%rax), %esi
callq 0x2270
movq %rax, %rdi
movq 0xd00f(%rip), %rsi      # 0x10fc8
movq %rsi, -0x210(%rbp)
callq 0x21e0
movq -0x210(%rbp), %rsi
movq %rax, %rdi
callq 0x21e0
movq -0x218(%rbp), %rdi
leaq 0x7120(%rip), %rsi      # 0xb102
callq 0x21a0
movq -0x210(%rbp), %rsi
movq %rax, %rdi
callq 0x21e0
leaq 0x7015(%rip), %rax      # 0xb012
movq %rax, -0xf8(%rbp)
movl $0x4, -0xfc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x208(%rbp)
movq -0xf8(%rbp), %rax
movq %rax, -0x200(%rbp)
leaq -0x139(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x22f0
movq -0x200(%rbp), %rsi
movq -0x1f8(%rbp), %rdx
leaq -0x138(%rbp), %rdi
callq 0x42d0
jmp 0x4056
movq -0x208(%rbp), %rsi
movl -0xfc(%rbp), %ecx
leaq -0x118(%rbp), %rdi
leaq -0x138(%rbp), %rdx
callq 0x8920
jmp 0x4078
leaq -0x138(%rbp), %rdi
callq 0x2100
leaq -0x139(%rbp), %rdi
callq 0x2210
leaq -0x118(%rbp), %rdi
callq 0x44c0
testb $0x1, %al
jne 0x40a5
jmp 0x414b
movq 0xcf2c(%rip), %rdi      # 0x10fd8
movq 0xcf15(%rip), %rsi      # 0x10fc8
callq 0x21e0
movq %rax, -0x220(%rbp)
jmp 0x40c1
movq -0x220(%rbp), %rdi
leaq 0x7051(%rip), %rsi      # 0xb120
callq 0x21a0
movq %rax, -0x228(%rbp)
jmp 0x40dd
movq -0x228(%rbp), %rdi
movq 0xcedd(%rip), %rsi      # 0x10fc8
callq 0x21e0
jmp 0x40f2
jmp 0x4259
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x411d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x2100
leaq -0x139(%rbp), %rdi
callq 0x2210
jmp 0x426e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x4380
jmp 0x426e
movq 0xce86(%rip), %rdi      # 0x10fd8
leaq 0x6ffd(%rip), %rsi      # 0xb156
callq 0x21a0
movq %rax, -0x230(%rbp)
jmp 0x4167
movq -0x230(%rbp), %rdi
movl -0xfc(%rbp), %esi
callq 0x22d0
movq %rax, -0x238(%rbp)
jmp 0x4182
movq -0x238(%rbp), %rdi
leaq 0x6fd7(%rip), %rsi      # 0xb167
callq 0x21a0
movq %rax, -0x240(%rbp)
jmp 0x419e
movq -0x240(%rbp), %rdi
movq -0xf8(%rbp), %rsi
callq 0x21a0
movq %rax, -0x248(%rbp)
jmp 0x41ba
movq -0x248(%rbp), %rdi
movq 0xce00(%rip), %rsi      # 0x10fc8
callq 0x21e0
jmp 0x41cf
leaq -0x118(%rbp), %rdi
callq 0x43e0
movq %rax, -0x148(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x4450
movq %rax, -0x150(%rbp)
leaq -0x148(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x4410
testb $0x1, %al
jne 0x420e
jmp 0x4257
leaq -0x148(%rbp), %rdi
callq 0x4480
movq %rax, %rsi
movq 0xcdb4(%rip), %rdi      # 0x10fd8
callq 0x2190
movq %rax, -0x250(%rbp)
jmp 0x4232
movq -0x250(%rbp), %rdi
movq 0xcd88(%rip), %rsi      # 0x10fc8
callq 0x21e0
jmp 0x4247
jmp 0x4249
leaq -0x148(%rbp), %rdi
callq 0x44a0
jmp 0x41e2
jmp 0x4259
leaq -0x118(%rbp), %rdi
callq 0x4380
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x22e0
nopw (%rax,%rax)