![]() |
| [[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]] |
|
|
#1 |
|
Posts: n/a
|
It is true that was STL gives you is just push_heap() and pop_heap() to manipulate heaps. There is no way to update the heap. Since heap is commonly used for priority queues I expected it to have update functionality implemented. I find it quite restrictive to have a priority queue where the priority of an item can't change!
Some time ago I implemented some templetized update_heap() function. The implementation is such that blends smoothly with the STL. The syntax of update_heap() is : void update_heap(CRanIt first, CRanIt last, CRanIt pos, CType *newval) or if you need to supply a compare functor : void update_heap(CRanIt first, CRanIt last, CRanIt pos, CType *newval, CPred pred) For my blog post about this code check this link. Code:
|
|
|
|
#2 |
|
Valued Member
Join Date: Aug 2005
Posts: 189
|
Hi,
It is indeed suprising to see that STL doesn't provide an algorithm to adjust one value of the heap. OTOH, i never needed it before Luckely, the STL is set up as such that it can easily be expanded. Though if you do, I suggest you stick to standard STL functions. The problem in this case is _Dist_type and _Val_type. Although probably provided by the STL you're using, these are by no means standard provided functions. So, if you try to use it with another implementation, it may possible break. AFAIK, the best change you have is to use iterator_traits to get these values. I also wondered why you pass newval by pointer to update_heap. a constant reference seems more suitable to me, or why not - to use the same spirit as the other heap functions - let the client update the iterator before calling update_heap. (and on the nitpicking side: it's best to avoid leading underscores )Bramz
___________________________________________
hi, i'm a signature viruz, plz set me as your signature and help me spread :) Bramz' warehouse | LiAR isn't a raytracer |
|
|
|
|
|
#3 | |
|
DevMaster Staff
Join Date: Sep 2005
Location: The Netherlands
Posts: 1,442
|
Quote:
Well, the only reason I can think of is that _[A-Z][A-Za-z0-9_]* and __[A-Za-z0-9_]* are reserved for implementation. So functions like _up_heap shouldn't cause a problem. The header guard _HEAP_EXTA_, however, might ![]() /END NITPICKING |
|
|
|
|
|
|
#4 |
|
Valued Member
Join Date: Aug 2005
Posts: 189
|
.oisyn,
you might check out section 17.4.3.1.2 of the standard plus its footnote to see that _[A-Za-z0-9_]* is reserved for names in global and ::std namespace as well. Since he hasn't put his functions in any namespace, that means ... exactly ![]() Besides, __[A-Za-z0-9_]* doesn't cover things like foo__bar which is reserved as well ... in any namespace ![]() Bramz
___________________________________________
hi, i'm a signature viruz, plz set me as your signature and help me spread :) Bramz' warehouse | LiAR isn't a raytracer Last edited by bramz : 09-15-2005 at 07:53 AM. |
|
|
|
|
|
#5 |
|
DevMaster Staff
Join Date: Sep 2005
Location: The Netherlands
Posts: 1,442
|
I stand corrected, I must've wrongly interpreted that paragraph the last time I read it.
and it looks like your virus is spreading ![]()
___________________________________________
C++ addict - Currently working on: the 3D engine for Tomb Raider: Underworld and Deus Ex 3. Last edited by .oisyn : 09-15-2005 at 08:05 AM. |
|
|
|
|
|
#6 | |
|
Valued Member
Join Date: Aug 2005
Posts: 189
|
Quote:
Yes, it's a rather nasty one ... ![]()
___________________________________________
hi, i'm a signature viruz, plz set me as your signature and help me spread :) Bramz' warehouse | LiAR isn't a raytracer |
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|