Updated answer
Tabs to 4x spaces
Code cleanup

removed unnecessary libraries.
rewrote search to be much faster(on average).
cleaned up comments.
rewrote how collisions are avoided when getting item weights.