Re: [boost] [GSoC] Heaps & Queues (draft proposal)

First of all, thank you, Andrew for your appreciation and Jeremiah for your information. I do not notice there exists d-ary in the BGL since I just focus on boost/pending and libs/pri_queue these days. But after a quick glance on the code in boost/graph/detail/d_ary_heap.hpp, I think that the container is supposed to have push_back() and pop()_back() because they are used directly in push() and pop(), This is something like the alias for vector type, not the parameter. Is that right or I just misunderstand the code in boost/graph/detail/d_ary_heap.hpp? As someone says: APIs design is main contributor to the Boost (I have read it today in somewhere in boost.org, but I can find it now :-( ). And I am lack of experience in APIs design for library. So I want to focus on my APIs design again. I know I am a bit annoying, but I want to do my best since it is my first time to join in GSoC. Feedback are welcome. It will be nice of you to do that. ==== description here ==== In order to be extendible, I would like to add iterator to the base class, which is more frequently used in programming, especially generic programming, than pointer. In some libraries, such as the STL, iterator is a bridge for container and algorithm. Since one of the goals of this project is to redevelop a new library for advance data structures and adaptors, I consider iterator to be necessary component to the library. Maybe it’ll take a little bit more memory, but in modern PCs, I think it acceptable.(*am I wrong about the usage of the iterator?*) template <class RandomAccessIterator, // iterator of the container class TreeNode, // key type class Comp = std::less<TreeNode>> class heap{ public: class iterator{ // implement iterator so that this class can be use as container // for other adaptors and algorithms public: TreeNode const& operator* () const; TreeNode const* operator->() const; iterator& operator++(); iterator operator++(int); bool operator== (iterator const& it); bool operator!= (iterator const& it); }; public: /* param: new_inserted points to the bottom of the container * where the new value has been inserted but not heapify. */ void insert(RandomAccessIterator new_inserted); void delete(RandomAccessIterator delete_node); void update(RandomAccessIterator update_node, TreeNode& new_node); // make the heap mutable RandomAccessIterator merge(RandomAccessIterator other_root); RandomAccessIterator getRoot(); RandomAccessIterator find(TreeNode& node); bool empty() const; size_type size() const; iterator begin() const; iterator end() const; void print() const; private: void print_recur() const; protected: RandomAccessIterator _root; }; NOTICE: operations print and print_recur is optional. But I prefer to include them because it'll be helpful when debugging the programs using this library. The class mentioned above is the base class for all the heap structures in the new library. The classes such as Fibonacci heap, relaxed heap, binomial heap and d-ary heap should inherit from this abstract class and add additional operations if needed. As the adaptor of heaps, the priority queue API may like: template< class RandomAccessIterator, class TreeNode, class Comp = std::less<TreeNode> class Container = fibonacci_heap<RandomAccessIterator, TreeNode, Comp>> class priority_queue{ public: /* param: new_inserted points to the place * where the new value has been inserted */ void push(RandomAccessIterator new_inserted); void pop(); // get the first value without popping it const TreeNode& front() const; TreeNode& front() ; RandomAccessIterator front() const; RandomAccessIterator find(TreeNode& node); void update(RandomAccessIterator update_node, TreeNode& new_node); // make the priority queue mutable RandomAccessIterator merge(RandomAccessIterator other_head); bool empty() const; size_type size() const; void print() const; private: void print_recur() const; protected: RandomAccessIterator _head; }; Thank you for your time. Yours sincerely, Tao Lin

On Thu, 8 Apr 2010, iaml wrote:
First of all, thank you, Andrew for your appreciation and Jeremiah for your information. I do not notice there exists d-ary in the BGL since I just focus on boost/pending and libs/pri_queue these days. But after a quick glance on the code in boost/graph/detail/d_ary_heap.hpp, I think that the container is supposed to have push_back() and pop()_back() because they are used directly in push() and pop(), This is something like the alias for vector type, not the parameter. Is that right or I just misunderstand the code in boost/graph/detail/d_ary_heap.hpp?
That sounds right -- it probably wants a Random Access Container that is also a Back Insertion Sequence. It would work with vector, deque, or the fixed_max_size_vector that is earlier in d_ary_heap.hpp. -- Jeremiah Willcock

That sounds right -- it probably wants a Random Access Container that is also a Back Insertion Sequence. It would work with vector, deque, or the fixed_max_size_vector that is earlier in d_ary_heap.hpp.
Yes, you are right. In it comments, it says container means random access container. Maybe array and list are less used in development. I still consider it's necessary to make them available for d-ary in the new library. So I want to rebuild d_ary_heap.hpp by using iterator in the new library. Will that be redundancy for Boost? Besides, my understanding on "A second requirement is that heaps may be "mutable", meaning that a value already stored in the heap can be modified and the heap efficiently updated to accommodate the new change" is that we can modify all the nodes in the key, not just the root. If my understanding was right, there would be the other reason to include d-ary in the new library becuse the original one in the BGL dose not support this operation ( operation update in d_ary_heap.hpp is only for root). Thank you for your time. Yours sincerely, Tao Lin

Firstly, I want to apologize for my conceit for saying: ** Benefit for Boost Heap is widely used in development such as heap sort, priority queue and other graph algorithm. It also can be the container for advanced data structures. But the heaps in boost/pending and libs/pri_queue is not extendable or highly abstract. This leads to the limited usage of this library. To redevelop a new library about heaps and priority queue more abstract and more user-friendly not only can broaden the user group of Boost, but also can fix the design deficiency in boost/pending and make it more conforms to the philosophy of Boost. in my proposal. These days, I have been preparing for my proposal, especially on API design. Now I know how hard it is to design the API. I can't imagine how much effort has been spent on boost/pending when the developers of Boost decide to code for it. I really appreciate their work and feel ashamed for saying that. Sorry! ;-(. Thank you for reading. Your sincerely Tao Lin
participants (2)
-
iaml
-
Jeremiah Willcock