Files
wow-weakauras/Random Trash/Hashing/1.lua
2025-05-15 20:37:50 +02:00

172 lines
4.4 KiB
Lua

local cc = {
"Gnaw",
"Hungering Cold",
"Bash",
"Cyclone",
"Entangling Roots",
"Hibernate",
"Maim",
"Pounce",
"Entrapment",
"Freezing Trap",
"Pin",
"Scare Beast",
"Scatter Shot",
"Intimidation",
"Ravage",
"Sonic Blast",
"Wyvern Sting",
"Deep Freeze",
"Dragon's Breath",
"Frost Nova",
"Polymorph",
"Shattered Barrier",
"Slow",
"Frostbolt",
"Hammer of Justice",
"Holy Wrath",
"Repentance",
"Seal of Justice",
"Turn Evil",
"Mind Control",
"Psychic Horror",
"Psychic Scream",
"Shackle Undead",
"Holy Word: Chastise",
"Sin and Punishment",
"Blind",
"Cheap Shot",
"Gouge",
"Kidney Shot",
"Sap",
"Earthbind Totem",
"Stoneclaw Totem",
"Hex",
"Banish",
"Death Coil",
"Fear",
"Howl of Terror",
"Intercept",
"Seduction",
"Shadowfury",
"Charge",
"Concussion Blow",
"Hamstring",
"Improved Hamstring",
"Intimidating Shout",
"Shockwave",
}
local hashtable = {}
local spellarray = {}
local function tonum(cchar)
if cchar == ":" then return 58 end
if cchar == "-" then return 45 end
if cchar == "!" then return 32 end
if cchar == "," then return 44 end
if cchar == "0" then return 48 end
if cchar == "1" then return 49 end
if cchar == "2" then return 50 end
if cchar == "3" then return 51 end
if cchar == "4" then return 52 end
if cchar == "5" then return 53 end
if cchar == "6" then return 54 end
if cchar == "7" then return 55 end
if cchar == "8" then return 56 end
if cchar == "9" then return 57 end
if cchar == "A" then return 65 end
if cchar == "B" then return 66 end
if cchar == "C" then return 67 end
if cchar == "D" then return 68 end
if cchar == "E" then return 69 end
if cchar == "F" then return 70 end
if cchar == "G" then return 71 end
if cchar == "H" then return 72 end
if cchar == "I" then return 73 end
if cchar == "J" then return 74 end
if cchar == "K" then return 75 end
if cchar == "L" then return 76 end
if cchar == "M" then return 77 end
if cchar == "N" then return 78 end
if cchar == "O" then return 79 end
if cchar == "P" then return 80 end
if cchar == "Q" then return 81 end
if cchar == "R" then return 82 end
if cchar == "S" then return 83 end
if cchar == "T" then return 84 end
if cchar == "U" then return 85 end
if cchar == "V" then return 86 end
if cchar == "W" then return 87 end
if cchar == "X" then return 88 end
if cchar == "Y" then return 89 end
if cchar == "Z" then return 90 end
if cchar == "a" then return 97 end
if cchar == "b" then return 98 end
if cchar == "c" then return 99 end
if cchar == "d" then return 100 end
if cchar == "e" then return 101 end
if cchar == "f" then return 102 end
if cchar == "g" then return 103 end
if cchar == "h" then return 104 end
if cchar == "i" then return 105 end
if cchar == "j" then return 106 end
if cchar == "k" then return 107 end
if cchar == "l" then return 108 end
if cchar == "m" then return 109 end
if cchar == "n" then return 110 end
if cchar == "o" then return 111 end
if cchar == "p" then return 112 end
if cchar == "q" then return 113 end
if cchar == "r" then return 114 end
if cchar == "s" then return 115 end
if cchar == "t" then return 116 end
if cchar == "u" then return 117 end
if cchar == "v" then return 118 end
if cchar == "w" then return 119 end
if cchar == "x" then return 120 end
if cchar == "y" then return 121 end
if cchar == "z" then return 122 end
end
local function findcollision(hash_table, array)
local collisions = 0
for k, v in ipairs(hash_table) do
for i = 1, table.getn(hash_table) do
if i ~= k then
if hash_table[i] == hash_table[k] then
collisions = collisions + 1
print(hash_table[i], hash_table[k], i, k, array[i], array[k])
end
end
end
end
return collisions
end
local function tohash(tempvar)
local charTable = {}
local hash = 0
for char in tempvar:gmatch("%a") do
charTable[#charTable + 1] = char
hash = hash + tonum(char)
hash = hash / table.getn(charTable)
end
hash = math.floor(hash * 10000)
return hash
--print(spellarray[hash], hash)
end
local function checkbase(spell)
if spellarray[tohash(spell)] == nil then return 0 end
if spellarray[tohash(spell)] == spell then return 1 end
end
for k, v in ipairs(cc) do
local hash = tohash(v)
hashtable[#hashtable] = hash
spellarray[hash] = v
end
findcollision(hashtable, cc)