Click here to Skip to main content
15,891,184 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Re SHFileOperation Pin
Bram van Kampen3-Sep-08 13:49
Bram van Kampen3-Sep-08 13:49 
QuestionModeless dialog - How do I (clear the contents of an edit box) Pin
simon alec smith3-Sep-08 10:59
simon alec smith3-Sep-08 10:59 
AnswerRe: Modeless dialog - How do I (clear the contents of an edit box) Pin
Bram van Kampen3-Sep-08 12:06
Bram van Kampen3-Sep-08 12:06 
GeneralRe: Modeless dialog - How do I (clear the contents of an edit box) Pin
simon alec smith3-Sep-08 12:54
simon alec smith3-Sep-08 12:54 
QuestionHTMLHelp on x64, linking Pin
Chris Losinger3-Sep-08 10:00
professionalChris Losinger3-Sep-08 10:00 
GeneralRe: HTMLHelp on x64, linking Pin
Perspx3-Sep-08 10:04
Perspx3-Sep-08 10:04 
GeneralRe: HTMLHelp on x64, linking Pin
Chris Losinger3-Sep-08 10:09
professionalChris Losinger3-Sep-08 10:09 
Questionfastest way to look up a string Pin
Jim Crafton3-Sep-08 9:05
Jim Crafton3-Sep-08 9:05 
I am working on a StringPool class. I'm trying to find the fastest way to look up a wchar_t* in an associative container. The current way I do this is to hash the string, and look up the hash value in the container. If it's not there, then add a new entry for it.

the code looks something like this:

size_t StringPool::find( const wchar_t* str, size_t length )
{
  size_t result = NoEntry;

  size_t hashID = hash(str,length);

  StringMapRangeT found = stringMap_.equal_range( hashID );
  StringMapIter current = found.first;

  size_t rangeCount = 0;
  while ( current != found.second ) {
    rangeCount ++;
    ++current;
  }

  current = found.first;
  if ( rangeCount == 1 ) {
    size_t idx = current->second;
    if ( idx < stringEntries_.size() ) {
      const StrEntry& entry = stringEntries_[idx];
      if ( entry.length == length ) {
        result = idx;
      }
    }
  }
  else {
    while ( current != found.second ) {
      size_t idx = current->second;
        if ( idx < stringEntries_.size() ) {
          const StrEntry& entry = stringEntries_[idx];
          if ( entry.length == length ) {
            if ( 0 == ::wmemcmp( entry.str, str, length ) ) {
              result = idx;
              break;
          }
        }
      }
      ++current ;
    }
  }
  return result;
}


where StrEntry is just a struct that holds info about a string instance, like the string pointer, the length, etc.

stringMap_ is a multimap defined like so: std::multimap<size_t,size_t>

The multimap is the slowest (as far as I can tell) element here. Is there a better container to use? This is particularly true when a new string is added, and I first see if it exists or not (which is where the above code is called), and if not, then the hash id is inserted into the stringMap_. The insert is (not surprisingly) kind of expensive, so I'm wondering if there's a better approach or container to use.

¡El diablo está en mis pantalones! ¡Mire, mire!

Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!

SELECT * FROM User WHERE Clue > 0
0 rows returned

Save an Orange - Use the VCF!
VCF Blog

AnswerRe: fastest way to look up a string Pin
Nemanja Trifunovic3-Sep-08 9:37
Nemanja Trifunovic3-Sep-08 9:37 
QuestionGetting VID and PID from device using UsbSer Pin
Roger Stoltz3-Sep-08 6:03
Roger Stoltz3-Sep-08 6:03 
QuestionSimple array-problem Pin
Joplinazz3-Sep-08 5:54
Joplinazz3-Sep-08 5:54 
AnswerRe: Simple array-problem Pin
toxcct3-Sep-08 6:05
toxcct3-Sep-08 6:05 
GeneralRe: Simple array-problem Pin
Joplinazz3-Sep-08 6:11
Joplinazz3-Sep-08 6:11 
GeneralRe: Simple array-problem Pin
toxcct3-Sep-08 6:24
toxcct3-Sep-08 6:24 
GeneralRe: Simple array-problem Pin
Joplinazz3-Sep-08 6:38
Joplinazz3-Sep-08 6:38 
AnswerRe: Simple array-problem Pin
Roger Stoltz3-Sep-08 6:31
Roger Stoltz3-Sep-08 6:31 
GeneralRe: Simple array-problem Pin
Joplinazz3-Sep-08 8:03
Joplinazz3-Sep-08 8:03 
QuestionCreating a UI thread with CWinThread Pin
sashoalm3-Sep-08 4:57
sashoalm3-Sep-08 4:57 
AnswerRe: Creating a UI thread with CWinThread Pin
Mark Salsbery3-Sep-08 5:06
Mark Salsbery3-Sep-08 5:06 
GeneralRe: Creating a UI thread with CWinThread Pin
sashoalm3-Sep-08 5:10
sashoalm3-Sep-08 5:10 
GeneralRe: Creating a UI thread with CWinThread Pin
Mark Salsbery3-Sep-08 5:20
Mark Salsbery3-Sep-08 5:20 
GeneralRe: Creating a UI thread with CWinThread Pin
sashoalm3-Sep-08 5:26
sashoalm3-Sep-08 5:26 
Questionifstream Pin
FrankMookie3-Sep-08 4:36
FrankMookie3-Sep-08 4:36 
AnswerRe: ifstream [modified] Pin
toxcct3-Sep-08 4:52
toxcct3-Sep-08 4:52 
GeneralRe: ifstream Pin
FrankMookie3-Sep-08 5:05
FrankMookie3-Sep-08 5:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.