If you're using a dictionary but doing a ContainsValue check it's a waste of time. Check existence of the key as thats ~O(1)
If you're using a dictionary but doing a ContainsValue check it's a waste of time. Check existence of the key as thats ~O(1)
"Programs should be written for people to read, and only incidentally for machines to execute." (Structure and Interpretation of Computer Programs, by Abelson and Sussman)
I use both ordered and unordered STL containers heavily in my code and have seen zero real performance drop in either case. Until you actually profile the code and check that it's causing a bottleneck or slowdown I'm gonna call bullshit on the 'costly' attribute.
I don't know what the C# alternatives are and whether you're calling it 'costly' because it's premature pessimization (due to incorrect container choice or what-not), but premature optimization is just as evil, and that seems to me to be what you're doing.
So, if you're calling it 'costly' because it's premature pessimization, what is the alternative? Hash table? What is the difference in speed between the containers (in Big O notation, not CPU cycles you dipshit, because you can 'control' the former, you can't control the latter -- nitpicker's corner: i'm obviously talking about the ALGORITHM, not the CODE)? What is the tradeoff? (For example hash containers need items hashed when added to the container, increasing the time it takes for new items to be added, etc etc)
Last edited by Cypher; 08-02-2009 at 01:08 AM.
Tested on a Dictionary (Dictionary<uint, string>) with 50 000 entries:
same with an Hashtable filled with 50000 entries
Code:static bool HashtableTest() { return Hashtable.ContainsKey(40000); } static bool TryGetValueTest() { string val; Dictionary.TryGetValue(40000, out val); return val == null ? false : true; } static bool ContainsTest() { return Dictionary.ContainsKey(40000); }
100,00% HashtableTest - 3613,7 ms - 10000000 calls - PerfTest.Program.HashtableTest()
84,49% ContainsKey - 3053,4 ms - 10000000 calls - System.Collections.Hashtable.ContainsKey(Object)
100,00% TryGetValueTest - 1918,1 ms - 10000000 calls - PerfTest.Program.TryGetValueTest()
81,33% TryGetValue - 1559,9 ms - 10000000 calls - System.Collections.Generic.Dictionary<TKey, TValue>.TryGetValue(TKey, TValue &)
100,00% ContainsTest - 1942,4 ms - 10000000 calls - PerfTest.Program.ContainsTest()
78,95% ContainsKey - 1533,5 ms - 10000000 calls - System.Collections.Generic.Dictionary<TKey, TValue>.ContainsKey(TKey)
But filling a Hashtable seems to be slightly faster:
100,00% Add - 24,565 ms - 50000 calls - System.Collections.Generic.Dictionary<TKey, TValue>.Add(TKey, TValue)100,00% Add - 22,420 ms - 50000 calls - System.Collections.Hashtable.Add(Object, Object)
Edit:
Wow I just tried it with an ArrayList (of course you can't compare Hastable/Dictionary to the arraylist)
but the results are really shocking:
static bool ArrayTest()
{
return ArrayList.Contains(40000);
}I had to stop the profiling because it took to long.100,00% Contains - 37463* ms - 4617 calls - System.Collections.ArrayList.Contains(Object)
Last edited by jockel; 08-02-2009 at 04:44 PM.
I found it.
Object descriptor field : OBJECT_FIELD_ENTRY is object's ID
for Item or Container, it's Item ID, and for GameObject,it's Gameobject ID
enum eObjectFields
{
OBJECT_FIELD_GUID = 0x0,
OBJECT_FIELD_TYPE = 0x8,
OBJECT_FIELD_ENTRY = 0xC, // Item ID or GameObject ID
OBJECT_FIELD_SCALE_X = 0x10,
OBJECT_FIELD_PADDING = 0x14,
TOTAL_OBJECT_FIELDS = 0x5
};
Finding mine and herb by its id is sure better than by its name.
Below are all mines and herbs and chests 's GameObject ID:
(from Wowhead: The first three letters say it all.)
Gatherer.Nodes.Names = {
["Small Thorium Vein"] = 324,
["Incendicite Mineral Vein"] = 1610,
["Copper Vein"] = 1731,
["Tin Vein"] = 1732,
["Silver Vein"] = 1733,
["Gold Vein"] = 1734,
["Iron Deposit"] = 1735,
["Mithril Deposit"] = 2040,
["Truesilver Deposit"] = 2047,
["Lesser Bloodstone Deposit"] = 2653,
["Indurium Mineral Vein"] = 19903,
["Ooze Covered Silver Vein"] = 73940,
["Ooze Covered Gold Vein"] = 73941,
["Ooze Covered Truesilver Deposit"] = 123309,
["Ooze Covered Mithril Deposit"] = 123310,
["Ooze Covered Thorium Vein"] = 123848,
["Dark Iron Deposit"] = 165658,
["Rich Thorium Vein"] = 175404,
["Ooze Covered Rich Thorium Vein"] = 177388,
["Hakkari Thorium Vein"] = 180215,
["Fel Iron Deposit"] = 181555,
["Adamantite Deposit"] = 181556,
["Khorium Vein"] = 181557,
["Rich Adamantite Deposit"] = 181569,
["Nethercite Deposit"] = 185877,
["Cobalt Deposit"] = 189978,
["Rich Cobalt Deposit"] = 189979,
["Saronite Deposit"] = 189980,
["Rich Saronite Deposit"] = 189981,
["Titanium Vein"] = 191133,
["Silverleaf"] = 1617,
["Peacebloom"] = 1618,
["Earthroot"] = 1619,
["Mageroyal"] = 1620,
["Briarthorn"] = 1621,
["Bruiseweed"] = 1622,
["Wild Steelbloom"] = 1623,
["Kingsblood"] = 1624,
["Grave Moss"] = 1628,
["Liferoot"] = 2041,
["Fadeleaf"] = 2042,
["Khadgar's Whisker"] = 2043,
["Wintersbite"] = 2044,
["Stranglekelp"] = 2045,
["Goldthorn"] = 2046,
["Firebloom"] = 2866,
["Purple Lotus"] = 142140,
["Arthas' Tears"] = 142141,
["Sungrass"] = 142142,
["Blindweed"] = 142143,
["Ghost Mushroom"] = 142144,
["Gromsblood"] = 142145,
["Golden Sansam"] = 176583,
["Dreamfoil"] = 176584,
["Mountain Silversage"] = 176586,
["Plaguebloom"] = 176587,
["Icecap"] = 176588,
["Black Lotus"] = 176589,
["Bloodthistle"] = 181166,
["Felweed"] = 181270,
["Dreaming Glory"] = 181271,
["Ragveil"] = 181275,
["Flame Cap"] = 181276,
["Terocone"] = 181277,
["Ancient Lichen"] = 181278,
["Netherbloom"] = 181279,
["Nightmare Vine"] = 181280,
["Mana Thistle"] = 181281,
["Netherdust Bush"] = 185881,
["Goldclover"] = 189973,
["Tiger Lily"] = 190169,
["Talandra's Rose"] = 190170,
["Lichbloom"] = 190171,
["Icethorn"] = 190172,
["Frozen Herb"] = 190175,
["Frost Lotus"] = 190176,
["Adder's Tongue"] = 191019,
["Firethorn"] = 191303,
["Hidden Strongbox"] = 2039,
["Giant Clam"] = 2744,
["Battered Chest"] = 2843,
["Tattered Chest"] = 2844,
["Solid Chest"] = 2850,
["Water Barrel"] = 3658,
["Barrel of Melon Juice"] = 3659,
["Armor Crate"] = 3660,
["Weapon Crate"] = 3661,
["Food Crate"] = 3662,
["Barrel of Milk"] = 3705,
["Barrel of Sweet Nectar"] = 3706,
["Alliance Strongbox"] = 3714,
["Box of Assorted Parts"] = 19019,
["Scattered Crate"] = 28604,
["Large Iron Bound Chest"] = 74447,
["Large Solid Chest"] = 74448,
["Large Battered Chest"] = 75293,
["Buccaneer's Strongbox"] = 123330,
["Large Mithril Bound Chest"] = 131978,
["Large Darkwood Chest"] = 131979,
["Horde Supply Crate"] = 142191,
["Un'Goro Dirt Pile"] = 157936,
["Blue Power Crystal"] = 164658,
["Green Power Crystal"] = 164659,
["Red Power Crystal"] = 164660,
["Yellow Power Crystal"] = 164661,
["Cleansed Night Dragon"] = 164881,
["Cleansed Songflower"] = 164882,
["Cleansed Windblossom"] = 164884,
["Bloodpetal Sprout"] = 164958,
["Cleansed Whipper Root"] = 174622,
["Blood of Heroes"] = 176213,
["Shellfish Trap"] = 176582,
["Practice Lockbox"] = 178244,
["Battered Footlocker"] = 179486,
["Waterlogged Footlocker"] = 179487,
["Dented Footlocker"] = 179492,
["Mossy Footlocker"] = 179493,
["Scarlet Footlocker"] = 179498,
["Burial Chest"] = 181665,
["Fel Iron Chest"] = 181798,
["Heavy Fel Iron Chest"] = 181800,
["Adamantite Bound Chest"] = 181802,
["Felsteel Chest"] = 181804,
["Glowcap"] = 182053,
["Wicker Chest"] = 184740,
["Primitive Chest"] = 184793,
["Solid Fel Iron Chest"] = 184930,
["Bound Fel Iron Chest"] = 184931,
["Bound Adamantite Chest"] = 184936,
["Netherwing Egg"] = 185915,
["Everfrost Chip"] = 193997,
}
btw:
The url : http://www.wowhead.com/?object=[objectid] can tell you requied skill level.
Last edited by starfish99; 08-18-2009 at 12:31 AM.