DriveHQ Start Menu
Cloud Drive Mapping
Folder Sync
Cloud Backup
True Drop Box
FTP/SFTP Hosting
Group Account
DriveHQ Start Menu
Online File Server
My Storage
|
Manage Shares
|
Publishes
|
Drop Boxes
|
Group Account
WebDAV Drive Mapping
Cloud Drive Home
|
WebDAV Guide
|
Drive Mapping Tool
|
Drive Mapping URL
Complete Data Backup
Backup Guide
|
Online Backup Tool
|
Cloud-to-Cloud Backup
FTP, Email & Web Service
FTP Home
|
FTP Hosting FAQ
|
Email Hosting
|
EmailManager
|
Web Hosting
Help & Resources
About
|
Enterprise Service
|
Partnership
|
Comparisons
|
Support
Quick Links
Security and Privacy
Download Software
Service Manual
Use Cases
Group Account
Online Help
Blog
Contact
Cloud Surveillance
Sign Up
Login
Features
Business Features
Online File Server
FTP Hosting
Cloud Drive Mapping
Cloud File Backup
Email Backup & Hosting
Cloud File Sharing
Folder Synchronization
Group Management
True Drop Box
Full-text Search
AD Integration/SSO
Mobile Access
IP Camera & DVR Solution
More...
Personal Features
Personal Cloud Drive
Backup All Devices
Mobile APPs
Personal Web Hosting
Sub-Account (for Kids)
Home/PC/Kids Monitoring
More...
Software
DriveHQ Drive Mapping Tool
DriveHQ FileManager
DriveHQ Online Backup
DriveHQ Mobile Apps
Pricing
Business Plans & Pricing
Personal Plans & Pricing
Price Comparison with Others
Feature Comparison with Others
Install Mobile App
Sign up
Creating account...
Invalid character in username! Only 0-9, a-z, A-Z, _, -, . allowed.
Username is required!
Invalid email address!
E-mail is required!
Password is required!
Password is invalid!
Password and confirmation do not match.
Confirm password is required!
I accept
Membership Agreement
Please read the Membership Agreement and check "I accept"!
Free Quick Sign-up
Sign-up Page
Log in
Signing in...
Username or e-mail address is required!
Password is required!
Keep me logged in
Quick Login
Forgot Password
Up
Upload
Download
Share
Publish
New Folder
New File
Copy
Cut
Delete
Paste
Rate
Upgrade
Rotate
Effect
Edit
Slide
History
// (C) Copyright Jeremiah Willcock 2004 // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_FENCED_PRIORITY_QUEUE_HPP #define BOOST_FENCED_PRIORITY_QUEUE_HPP #include
#include
#include
#include
// Fenced priority queue // Jeremiah Willcock // This class implements a fenced priority queue. This is similar to // a normal priority queue (sorts its members, and only returns the // first), except that members cannot be sorted around a "fence" that // can be placed into the buffer. This fence is inserted using the // fence() member function or (possibly) implicitly by the top() and // pop() methods, and is removed automatically when the elements // around it are popped. // The implementation is as follows: Q is an unsorted queue that // contains the already-sorted list data, and PQ is a priority queue // that contains new elements (since the last fence) that have yet to // be sorted. New elements are inserted into PQ, and a fence moves // all elements in PQ into the back of Q in sorted order. Elements // are then popped from the front of Q, and if that is empty the front // of PQ. namespace boost { template
, bool implicit_fence = true, class Buffer = boost::queue
> class fenced_priority_queue { public: typedef T value_type; typedef typename Buffer::size_type size_type; fenced_priority_queue(const Compare _comp = Compare() ) : PQ(_comp) {} void push(const T& data); void pop(void); T& top(void); const T& top(void) const; size_type size(void) const; bool empty(void) const; void fence(void); private: void fence(void) const; //let them mutable to allow const version of top and the same //semantics with non-constant version. Rich Lee mutable std::priority_queue
, Compare> PQ; mutable Buffer Q; }; template
inline void fenced_priority_queue
:: push(const T &t) { // Push a new element after the last fence. This puts it into the // priority queue to be sorted with all other elements in its // partition. PQ.push(t); } template
inline void fenced_priority_queue
:: pop(void) { // Pop one element from the front of the queue. Removes from the // already-sorted part of the queue if it is non-empty, otherwise // removes from the new-element priority queue. Runs an implicit // "fence" operation if the implicit_fence template argument is // true. if (implicit_fence) fence(); if ( !Q.empty() ) Q.pop(); else PQ.pop(); } template
inline T& fenced_priority_queue
:: top(void) { // Get the top element from the queue. This element comes from Q if // possible, otherwise from PQ. Causes an implicit "fence" // operation if the implicit_fence template argument is true. if (implicit_fence) fence(); if ( !Q.empty() ) return Q.top(); else //std::priority_queue only have const version of top. Rich Lee return const_cast
(PQ.top()); } template
inline const T& fenced_priority_queue
:: top(void) const { if (implicit_fence) fence(); if ( !Q.empty() ) return Q.top(); else return PQ.top(); } template
inline typename fenced_priority_queue
::size_type fenced_priority_queue
:: size(void) const { // Returns the size of the queue (both parts together). return Q.size() + PQ.size(); } template
inline bool fenced_priority_queue
:: empty(void) const { // Returns if the queue is empty, i.e. both parts are empty. return Q.empty() && PQ.empty(); } template
inline void fenced_priority_queue
:: fence(void) { // Perform a fence operation. Remove elements from PQ in sorted // order and insert them in the back of Q. while ( !PQ.empty() ) { Q.push(PQ.top()); PQ.pop(); } } template
inline void fenced_priority_queue
:: fence(void) const { // Perform a fence operation. Remove elements from PQ in sorted // order and insert them in the back of Q. while ( !PQ.empty() ) { Q.push(PQ.top()); PQ.pop(); } } } #endif /* BOOST_FENCED_PRIORITY_QUEUE_HPP */
fenced_priority_queue.hpp
Page URL
File URL
Prev
6/21
Next
Download
( 5 KB )
Note: The DriveHQ service banners will NOT be displayed if the file owner is a paid member.
Comments
Total ratings:
0
Average rating:
Not Rated
Would you like to comment?
Join DriveHQ
for a free account, or
Logon
if you are already a member.