[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    hash map?
From:       Michael Thaler <michael.thaler () physik ! tu-muenchen ! de>
Date:       2006-07-03 13:03:01
Message-ID: 200607031503.01899.michael.thaler () physik ! tu-muenchen ! de
[Download RAW message or body]

Hello,

I am working on porting the SIOX tool from gimp to Krita. The SIOX tool uses a 
hash_map to do some caching. For example it uses the two functions

static gboolean
siox_cache_remove_bg (gpointer key,
                      gpointer value,
                      gpointer user_data)
{
  classresult *cr = value;

  return (cr->bgdist < cr->fgdist);
}

static gboolean
siox_cache_remove_fg (gpointer key,
                      gpointer value,
                      gpointer user_data)
{
  classresult *cr = value;

  return (cr->bgdist >= cr->fgdist);
}

to remove pairs from the cache using the following functions:

  if (refinement & SIOX_REFINEMENT_ADD_FOREGROUND)
    g_hash_table_foreach_remove (state->cache, siox_cache_remove_bg, NULL);

  if (refinement & SIOX_REFINEMENT_ADD_BACKGROUND)
    g_hash_table_foreach_remove (state->cache, siox_cache_remove_fg, NULL);

I looked at the STL and at Qt, but they don't include hash maps. However, 
there is an SGI extension for the STL which includes hash_map:

I used the following program to test it (from Thinking in C++):

#include <iostream>
#include <map>
#include <ctime>

#ifdef __GNUC__
      #if __GNUC__ < 3
        #include <hash_map.h>
        namespace Sgi { using ::hash_map; }; // inherit globals
      #else
        #include <ext/hash_map>
        #if __GNUC_MINOR__ == 0
          namespace Sgi = std;               // GCC 3.0
        #else
          namespace Sgi = ::__gnu_cxx;       // GCC 3.1 and later
        #endif
      #endif
      #else      // ...  there are other compilers, right?
        namespace Sgi = std;
      #endif

using namespace std;

int main(){
  Sgi::hash_map<int, int> hm;
  map<int, int> m;
  clock_t ticks = clock();
  for(int i = 0; i < 100; i++)
    for(int j = 0; j < 1000; j++)
      m.insert(make_pair(j,j));
  cout << "map insertions: " 
    << clock() - ticks << endl;
  ticks = clock();
  for(int i = 0; i < 100; i++)
    for(int j = 0; j < 1000; j++)
      hm.insert(make_pair(j,j));
  cout << "hash_map insertions: " 
    << clock() - ticks << endl;
  ticks = clock();
  for(int i = 0; i < 100; i++)
    for(int j = 0; j < 1000; j++)
      m[j];
  cout << "map::operator[] lookups: " 
    << clock() - ticks << endl;
  ticks = clock();
  for(int i = 0; i < 100; i++)
    for(int j = 0; j < 1000; j++)
      hm[j];
  cout << "hash_map::operator[] lookups: "
    << clock() - ticks << endl;
  ticks = clock();
  for(int i = 0; i < 100; i++)
    for(int j = 0; j < 1000; j++)
      m.find(j);
  cout << "map::find() lookups: "
    << clock() - ticks << endl;
  ticks = clock();
  for(int i = 0; i < 100; i++)
    for(int j = 0; j < 1000; j++)
      hm.find(j);
  cout << "hash_map::find() lookups: " 
    << clock() - ticks << endl;
}

Since Krita is part of KOffice, I am not sure if it is o.k. to use SGI's 
hash_map for Krita because it is not part of the STL. If not, is there any 
other hash map that I could use for Krita?

Greetings,
Michael
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic