.NET HashTable По сравнению со Словарем - Словарь может быть столь же быстрой?

А-ч, vsprintf () был вещью, которую я пропускал. Я могу использовать это для передачи списка аргумента переменной непосредственно printf ():

#include <stdarg.h>
#include <stdio.h>

void DBG_PrintImpl(char * format, ...)
{
    char buffer[256];
    va_list args;
    va_start(args, format);
    vsprintf(buffer, format, args);
    printf("%s", buffer);
    va_end(args);
}

Тогда обертка все это в макросе.

269
задан John Saunders 14 March 2010 в 06:47
поделиться

3 ответа

System.Collections.Generic.Dictionary and System.Collections.Hashtable classes both maintain a hash table data structure internally. None of them guarantee preserving the order of items.

Leaving boxing/unboxing issues aside, most of the time, they should have very similar performance.

The primary structural difference between them is that Dictionary relies on chaining (maintaining a list of items for each hash table bucket) to resolve collisions whereas Hashtable uses rehashing for collision resolution (when a collision occurs, tries another hash function to map the key to a bucket).

There is little benefit to use Hashtable class if you are targeting for .NET Framework 2.0+. It's effectively rendered obsolete by Dictionary.

290
ответ дан 23 November 2019 в 02:21
поделиться

Both are effectively the same class (you can look at the disassembly). HashTable was created first before .Net had generics. Dictionary, however is a generic class and gives you strong typing benefits. I would never use HashTable since Dictionary costs you nothing to use.

11
ответ дан 23 November 2019 в 02:21
поделиться

Еще одно важное отличие состоит в том, что тип Hashtable поддерживает одновременное использование нескольких считывателей без блокировки и одного записывающего устройства. , а Dictionary - нет.

23
ответ дан 23 November 2019 в 02:21
поделиться
Другие вопросы по тегам:

Похожие вопросы: