Min-Heap and Hash Table help

Justin Whear justin at economicmodeling.com
Mon Apr 2 15:53:55 PDT 2012


On Tue, 03 Apr 2012 00:47:56 +0200, Chris Pons wrote:

> I'm trying to work with and implement and priority queue( min-heap ) and
> a hash table. This is the first time I've worked with these data
> structures so I looked up some information about them to gain an
> understanding.
> 
>  From what I read, a min-heap is a binary tree that is sorted by a
> priority. In my case I have a struct called Node for an A* algorithm
> that I wanted to place in a min-heap sorted by an integer, their f
> score. Initially the min-heap will only have one item in it with others
> added later.
> 
> How would I create a min-heap sorted by fScore? Will the list stay
> sorted after I add a new node?
> 
> As far as hash tables goes, it seems like I need to use an associative
> array, is that right?
> 
> What exactly would the key/hash be? How would I implement this if the
> hash table is supposed to contain the struct Node?

BinaryHeap in std.container can be made to work as a min-heap, in fact 
the documentation specifically mentions such a use: http://dlang.org/
phobos/std_container.html#BinaryHeap


More information about the Digitalmars-d-learn mailing list