コード例 #1
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  if (argc != 4)
    ACE_ERROR_RETURN ((LM_ERROR, "usage: %s tablesize file1 file2\n",
                       argv[0]), -1);
  else
    {
      int total = ACE_OS::atoi (argv[1]);

      if (!ACE_OS::freopen (argv[2], ACE_TEXT("r"), stdin))
        ACE_OS::perror (argv[0]), ACE_OS::exit (1);

      MAP_MANAGER hash (total);

      ACE_TCHAR key[MAX_KEY_LEN];

      while (ACE_OS::fgets (key, sizeof key, stdin))
        // stream ops are just too slow!!
        {
          ACE_TString string (key);
          hash.bind (string, string);
        }

      fclose (stdin);

      MAP_MANAGER::ITERATOR iterator (hash);

      for (MAP_MANAGER::ENTRY *entry = 0;
           iterator.next (entry) != 0;
           iterator.advance ())
        ACE_DEBUG ((LM_DEBUG, "%s %s\n",
                    entry->ext_id_.fast_rep (),
                    entry->int_id_.fast_rep ()));

      if (!ACE_OS::freopen (argv[3], ACE_TEXT("r"), stdin))
        ACE_OS::perror (argv[0]), exit (1);

      while (ACE_OS::fgets (key, sizeof key, stdin))
        {
          ACE_TString name (key);
          ACE_TString value;
          assert (hash.find (name, value) != -1);
          assert (name == value);
        }

      if (!ACE_OS::freopen (argv[3], ACE_TEXT("r"), stdin))
        ACE_OS::perror (argv[0]), exit (1);

      while (ACE_OS::fgets (key, sizeof key, stdin))
        {
          ACE_TString string (key);
          assert (hash.unbind (string) != -1);
        }

      assert (hash.current_size () == 0);

      fclose (stdin);
    }

  return 0;
}
コード例 #2
0
static void
test_map_manager (size_t table_size,
                  size_t iterations,
                  int test_iterators)
{
    MAP_MANAGER map (table_size);
    TYPE i;
    TYPE j = 0;
    ssize_t k;

    for (i = 0; i < iterations; ++i)
        ACE_ASSERT (map.bind (i, i) != -1);

    if (test_iterators)
    {
        {
            i = 0;

            ITERATOR end = map.end ();
            for (ITERATOR iter = map.begin ();
                    iter != end;
                    ++iter)
            {
                MAP_ENTRY &entry = *iter;
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%d|%d|%d)"),
                            i,
                            entry.ext_id_,
                            entry.int_id_));
                ++i;
            }

            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("\n")));
            ACE_ASSERT (i == iterations);
        }

        {
            i = 0;
            MAP_ENTRY *entry = 0;

            for (ITERATOR iterator (map);
                    iterator.next (entry) != 0;
                    iterator.advance ())
            {
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%d|%d|%d)"),
                            i,
                            entry->ext_id_,
                            entry->int_id_));
                ++i;
            }

            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("\n")));
            ACE_ASSERT (i == iterations);
        }

        {
            k = iterations - 1;
            REVERSE_ITERATOR rend = map.rend ();

            for (REVERSE_ITERATOR iter = map.rbegin ();
                    iter != rend;
                    ++iter)
            {
                MAP_ENTRY &entry = *iter;
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%d|%d|%d)"),
                            k,
                            entry.ext_id_,
                            entry.int_id_));
                k--;
            }

            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("\n")));
            ACE_ASSERT (k == -1);
        }

        {
            k = iterations - 1;
            MAP_ENTRY *entry = 0;

            for (REVERSE_ITERATOR iterator (map);
                    iterator.next (entry) != 0;
                    iterator.advance ())
            {
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%d|%d|%d)"),
                            k,
                            entry->ext_id_,
                            entry->int_id_));
                k--;
            }

            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("\n")));
            ACE_ASSERT (k == -1);
        }

        {
            i = 0;

            MAP_MANAGER::iterator end = map.end ();
            for (MAP_MANAGER::iterator iter = map.begin ();
                    iter != end;
                    ++iter)
            {
                MAP_MANAGER::ENTRY &entry = *iter;
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%d|%d|%d)"),
                            i,
                            entry.ext_id_,
                            entry.int_id_));
                ++i;
            }

            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("\n")));
            ACE_ASSERT (i == iterations);
        }

        {
            i = 0;
            MAP_MANAGER::ENTRY *entry = 0;

            for (MAP_MANAGER::ITERATOR iterator (map);
                    iterator.next (entry) != 0;
                    iterator.advance ())
            {
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%d|%d|%d)"),
                            i,
                            entry->ext_id_,
                            entry->int_id_));
                ++i;
            }

            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("\n")));
            ACE_ASSERT (i == iterations);
        }

        {
            k = iterations - 1;
            MAP_MANAGER::reverse_iterator rend = map.rend ();

            for (MAP_MANAGER::reverse_iterator iter = map.rbegin ();
                    iter != rend;
                    ++iter)
            {
                MAP_ENTRY &entry = *iter;
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%d|%d|%d)"),
                            k,
                            entry.ext_id_,
                            entry.int_id_));
                k--;
            }

            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("\n")));
            ACE_ASSERT (k == -1);
        }

        {
            k = iterations - 1;
            MAP_MANAGER::ENTRY *entry = 0;

            for (MAP_MANAGER::REVERSE_ITERATOR iterator (map);
                    iterator.next (entry) != 0;
                    iterator.advance ())
            {
                ACE_DEBUG ((LM_DEBUG,
                            ACE_TEXT ("(%d|%d|%d)"),
                            k,
                            entry->ext_id_,
                            entry->int_id_));
                k--;
            }

            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("\n")));
            ACE_ASSERT (k == -1);
        }
    }

    for (i = 0; i < iterations; ++i)
    {
        ACE_ASSERT (map.find (i, j) != -1);
        ACE_ASSERT (i == j);
    }

    size_t remaining_entries = iterations;
    for (i = 0; i < iterations; ++i)
    {
        ACE_ASSERT (map.unbind (i) != -1);
        --remaining_entries;
        ACE_ASSERT (map.current_size () == remaining_entries);
    }

    //
    // This is extra for the map manager.
    //
    for (i = 0; i < iterations; ++i)
        ACE_ASSERT (map.bind (i, i) != -1);

    // Unbind in one swoop.
    map.unbind_all ();
    ACE_ASSERT (map.current_size () == 0);

    for (i = 0; i < iterations; ++i)
        ACE_ASSERT (map.bind (i, i) != -1);

    // Unbind one at a time.
    MAP_MANAGER::iterator end = map.end ();
    while (1)
    {
        MAP_MANAGER::iterator iter = map.begin ();
        if (iter == end)
            break;
        ACE_ASSERT (map.unbind ((*iter).ext_id_) != -1);
    }

    ACE_ASSERT (map.current_size () == 0);
}