本文整理汇总了C++中std::deque类的典型用法代码示例。如果您正苦于以下问题:C++ deque类的具体用法?C++ deque怎么用?C++ deque使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了deque类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pops
void ConsumerStateTable::pops(std::deque<KeyOpFieldsValuesTuple> &vkco, std::string /*prefix*/)
{
static std::string luaScript =
"local ret = {}\n"
"local keys = redis.call('SPOP', KEYS[1], ARGV[1])\n"
"local n = table.getn(keys)\n"
"for i = 1, n do\n"
"local key = keys[i]\n"
"local values = redis.call('HGETALL', KEYS[2] .. key)\n"
"table.insert(ret, {key, values})\n"
"end\n"
"return ret\n";
static std::string sha = loadRedisScript(m_db, luaScript);
RedisCommand command;
command.format(
"EVALSHA %s 2 %s %s: %d ''",
sha.c_str(),
getKeySetName().c_str(),
getTableName().c_str(),
POP_BATCH_SIZE);
RedisReply r(m_db, command);
auto ctx0 = r.getContext();
vkco.clear();
// if the set is empty, return an empty kco object
if (ctx0->type == REDIS_REPLY_NIL)
{
return;
}
assert(ctx0->type == REDIS_REPLY_ARRAY);
size_t n = ctx0->elements;
vkco.resize(n);
for (size_t ie = 0; ie < n; ie++)
{
auto& kco = vkco[ie];
auto& values = kfvFieldsValues(kco);
assert(values.empty());
auto& ctx = ctx0->element[ie];
assert(ctx->elements == 2);
assert(ctx->element[0]->type == REDIS_REPLY_STRING);
std::string key = ctx->element[0]->str;
kfvKey(kco) = key;
assert(ctx->element[1]->type == REDIS_REPLY_ARRAY);
auto ctx1 = ctx->element[1];
for (size_t i = 0; i < ctx1->elements / 2; i++)
{
FieldValueTuple e;
fvField(e) = ctx1->element[i * 2]->str;
fvValue(e) = ctx1->element[i * 2 + 1]->str;
values.push_back(e);
}
// if there is no field-value pair, the key is already deleted
if (values.empty())
{
kfvOp(kco) = DEL_COMMAND;
}
else
{
kfvOp(kco) = SET_COMMAND;
}
}
}
示例2: cycle_focus
//.........这里部分代码省略.........
{
const handler_list::iterator i = std::find(handlers.begin(),handlers.end(),ptr);
if(i != handlers.end() && (*i)->requires_event_focus()) {
focused_handler = i;
}
}
void context::add_staging_handlers()
{
std::copy(staging_handlers.begin(), staging_handlers.end(), std::back_inserter(handlers));
staging_handlers.clear();
}
context::~context()
{
for (sdl_handler* h : handlers)
{
if (h->has_joined())
{
h->has_joined_ = false;
}
if (h->has_joined_global())
{
h->has_joined_global_ = false;
}
}
}
// This object stores all the event handlers. It is a stack of event 'contexts'.
// a new event context is created when e.g. a modal dialog is opened, and then
// closed when that dialog is closed. Each context contains a list of the handlers
// in that context. The current context is the one on the top of the stack.
// The global context must always be in the first position.
std::deque<context> event_contexts;
std::vector<pump_monitor*> pump_monitors;
pump_monitor::pump_monitor() {
pump_monitors.push_back(this);
}
pump_monitor::~pump_monitor() {
pump_monitors.erase(
std::remove(pump_monitors.begin(), pump_monitors.end(), this),
pump_monitors.end());
}
event_context::event_context()
{
event_contexts.emplace_back();
}
event_context::~event_context()
{
assert(event_contexts.empty() == false);
event_contexts.pop_back();
}
sdl_handler::sdl_handler(const bool auto_join) :
has_joined_(false),
has_joined_global_(false)
{
if(auto_join) {
示例3: GetActions
void cHpiSubProviderReset::GetActions( std::deque<HpiAction>& actions ) const
{
actions.clear();
actions.push_back( HpiAction( 1, L"TODO" ) );
}
示例4: addLoopIntoQueue
// Recurse through all subloops and all loops into LQ.
static void addLoopIntoQueue(Loop *L, std::deque<Loop *> &LQ) {
LQ.push_back(L);
for (Loop::reverse_iterator I = L->rbegin(), E = L->rend(); I != E; ++I)
addLoopIntoQueue(*I, LQ);
}
示例5: addRegionIntoQueue
// Recurse through all subregions and all regions into RQ.
static void addRegionIntoQueue(Region &R, std::deque<Region *> &RQ) {
RQ.push_back(&R);
for (const auto &E : R)
addRegionIntoQueue(*E, RQ);
}
示例6: GenerateFaceIndicators
void GenerateFaceIndicators(const int &sampleIdx,
std::vector<double> &eyesHeightVec,
FaceFeature &faceFeatures,
std::deque<InfoPERCLOS> &PERCLOSDeque,
std::deque<InfoBLINK> &BLINKDeque,
const double &intervalTime)
{
double eyesHeight = 0, lastEyesHeight = faceFeatures.lastHeight;
double PERCLOS = 0, MICROSLEEP = 0, MICROSLEEPTime = faceFeatures.MICROSLEEPTime, BLINK = 0;
double eyesHeight_b = faceFeatures.Height_Baseline;
//Find the min size between two eyes.
if (!eyesHeightVec.empty()) {
sort(eyesHeightVec.begin(), eyesHeightVec.end(), SortBigger);
eyesHeight = eyesHeightVec.front();
if(eyesHeight > 2*eyesHeight_b )
eyesHeight = 2*eyesHeight_b;
}
else {
//Negative, if can NOT detect eyes correctly
eyesHeight = lastEyesHeight;
}
/*********************************************/
/* PERCLOS: Percentage of eye closure */
/*********************************************/
InfoPERCLOS perclosInfo;
perclosInfo.time = intervalTime;
if(!PERCLOSDeque.empty()){
/// Calculate the number of frames in fixed time
if (eyesHeight < faceFeatures.Height_Baseline * THRESHOLD_PERCLOS) {
perclosInfo.eyePERCLOS = 1; // eye closed
perclosInfo.timePERCLOS = PERCLOSDeque.back().timePERCLOS +intervalTime;
}
else {
perclosInfo.eyePERCLOS = 0;
perclosInfo.timePERCLOS = PERCLOSDeque.back().timePERCLOS;
}
perclosInfo.winTimePERCLOS = PERCLOSDeque.back().winTimePERCLOS + intervalTime;
//! Only focus on the fixed time interval.
while(perclosInfo.winTimePERCLOS > TIME_PERCLOS_WINDOW)
{
perclosInfo.winTimePERCLOS -= PERCLOSDeque.front().time;
if(PERCLOSDeque.front().eyePERCLOS == 1)
{
perclosInfo.timePERCLOS -= PERCLOSDeque.front().time;
}
PERCLOSDeque.pop_front();
}
//cout << "time PERCLOS: " << perclosInfo.timePERCLOS << endl;
}
else
{// The first frames without any PERCLOSInfo
if (eyesHeight < faceFeatures.Height_Baseline * THRESHOLD_PERCLOS) {
perclosInfo.eyePERCLOS = 1;
perclosInfo.timePERCLOS = intervalTime;
}
else {
perclosInfo.eyePERCLOS = 0;
perclosInfo.timePERCLOS = 0;
}
perclosInfo.winTimePERCLOS = intervalTime;
}
PERCLOSDeque.push_back(perclosInfo);
//! PERCLOS
if(perclosInfo.winTimePERCLOS < TIME_PERCLOS_WINDOW / 2)
PERCLOS = 0;//In first time interval too high value
else
PERCLOS = perclosInfo.timePERCLOS / perclosInfo.winTimePERCLOS;
/************************************************/
/* Statistics of Continuous Eye Closure */
/* MICROSLEEP: ND: 0~0.5 */
/* SD: 0.5~1 */
/* MD: 1~2 */
/* VD: 2~4 */
/* ED: 4~ */
/************************************************/
if (eyesHeight < faceFeatures.Height_Baseline * THRESHOLD_CLOSURE) {
MICROSLEEPTime += intervalTime;
}
else {
MICROSLEEPTime -= intervalTime;
MICROSLEEPTime = MICROSLEEPTime > 0 ? MICROSLEEPTime : 0;
}
//! When MICROSLEEPTime not equal to 0, Update the MICROSLEEP
if (MICROSLEEPTime < 0.5)
MICROSLEEP = 0.25 * MICROSLEEPTime; //Alert
else if (MICROSLEEPTime >= 0.5 && MICROSLEEPTime < 1)
MICROSLEEP = 0.5 * MICROSLEEPTime - 0.125; //Slightly Drowsy
else if (MICROSLEEPTime >= 1 && MICROSLEEPTime < 2)
MICROSLEEP = 0.25 * MICROSLEEPTime + 0.125; //Moderately Drowsy
else if(MICROSLEEPTime >= 2 && MICROSLEEPTime < 4)
MICROSLEEP = 0.125 * MICROSLEEPTime + 0.375; //Very Drowsy
else if(MICROSLEEPTime >= 4 && MICROSLEEPTime < 5)
//.........这里部分代码省略.........
示例7: freeGeneratorStack
namespace pyston {
static uint64_t next_stack_addr = 0x4270000000L;
static std::deque<uint64_t> available_addrs;
// There should be a better way of getting this:
#define PAGE_SIZE 4096
#define INITIAL_STACK_SIZE (8 * PAGE_SIZE)
#define STACK_REDZONE_SIZE PAGE_SIZE
#define MAX_STACK_SIZE (4 * 1024 * 1024)
static std::unordered_map<void*, BoxedGenerator*> s_generator_map;
static_assert(THREADING_USE_GIL, "have to make the generator map thread safe!");
class RegisterHelper {
private:
void* frame_addr;
public:
RegisterHelper(BoxedGenerator* generator, void* frame_addr) : frame_addr(frame_addr) {
s_generator_map[frame_addr] = generator;
}
~RegisterHelper() {
assert(s_generator_map.count(frame_addr));
s_generator_map.erase(frame_addr);
}
};
static void freeGeneratorStack(BoxedGenerator* g) {
if (g->stack_begin == NULL)
return;
available_addrs.push_back((uint64_t)g->stack_begin);
// Limit the number of generator stacks we keep around:
if (available_addrs.size() > 5) {
uint64_t addr = available_addrs.front();
available_addrs.pop_front();
int r = munmap((void*)(addr - MAX_STACK_SIZE), MAX_STACK_SIZE);
assert(r == 0);
}
g->stack_begin = NULL;
}
Context* getReturnContextForGeneratorFrame(void* frame_addr) {
BoxedGenerator* generator = s_generator_map[frame_addr];
assert(generator);
return generator->returnContext;
}
void generatorEntry(BoxedGenerator* g) {
{
assert(g->cls == generator_cls);
assert(g->function->cls == function_cls);
threading::pushGenerator(g, g->stack_begin, g->returnContext);
try {
RegisterHelper context_registerer(g, __builtin_frame_address(0));
// call body of the generator
BoxedFunctionBase* func = g->function;
Box** args = g->args ? &g->args->elts[0] : nullptr;
callCLFunc<ExceptionStyle::CXX>(func->f, nullptr, func->f->numReceivedArgs(), func->closure, g,
func->globals, g->arg1, g->arg2, g->arg3, args);
} catch (ExcInfo e) {
// unhandled exception: propagate the exception to the caller
g->exception = e;
}
// we returned from the body of the generator. next/send/throw will notify the caller
g->entryExited = true;
threading::popGenerator();
}
swapContext(&g->context, g->returnContext, 0);
}
Box* generatorIter(Box* s) {
return s;
}
// called from both generatorHasNext and generatorSend/generatorNext (but only if generatorHasNext hasn't been called)
template <ExceptionStyle S> static bool generatorSendInternal(BoxedGenerator* self, Box* v) noexcept(S == CAPI) {
STAT_TIMER(t0, "us_timer_generator_switching", 0);
if (!self->returnContext && v != None) {
if (S == CAPI) {
PyErr_SetString(TypeError, "can't send non-None value to a just-started generator");
return true;
} else
raiseExcHelper(TypeError, "can't send non-None value to a just-started generator");
}
if (self->running) {
if (S == CAPI) {
PyErr_SetString(ValueError, "generator already executing");
return true;
} else
raiseExcHelper(ValueError, "generator already executing");
//.........这里部分代码省略.........
示例8: stri__wrap_dynamic
/** Dynamic word wrap algorithm
* (Knuth's word wrapping algorithm that minimizes raggedness of formatted text)
*
* @param wrap_after [out]
* @param nwords number of "words"
* @param width_val maximal desired out line width
* @param exponent_val cost function exponent
* @param widths_orig ith word width original
* @param widths_trim ith word width trimmed
* @param add_para_1
* @param add_para_a
*
* @version 0.1-?? (Bartek Tartanus)
* original implementation
*
* @version 0.2-2 (Marek Gagolewski, 2014-04-30)
* BreakIterator usage mods
*
* @version 0.4-1 (Marek Gagolewski, 2014-12-06)
* new args: add_para_1, add_para_n,
* cost of the last line is zero
*/
void stri__wrap_dynamic(std::deque<R_len_t>& wrap_after,
R_len_t nwords, int width_val, double exponent_val,
const std::vector<R_len_t>& widths_orig,
const std::vector<R_len_t>& widths_trim,
int add_para_1, int add_para_n)
{
#define IDX(i,j) (i)*nwords+(j)
vector<double> cost(nwords*nwords);
// where cost[IDX(i,j)] == cost of printing words i..j in a single line, i<=j
// calculate costs:
// there is some "punishment" for leaving blanks at the end of each line
// (number of "blank" codepoints ^ exponent_val)
for (int i=0; i<nwords; i++) {
int sum = 0;
for (int j=i; j<nwords; j++) {
if (j > i) {
if (cost[IDX(i,j-1)] < 0.0) { // already Inf
cost[IDX(i,j)] = -1.0; // Inf
continue;
}
else {
sum -= widths_trim[j-1];
sum += widths_orig[j-1];
}
}
sum += widths_trim[j];
int ct = width_val - sum;
if (i == 0) ct -= add_para_1;
else ct -= add_para_n;
if (j == nwords-1) { // last line == cost 0
if (j == i || ct >= 0)
cost[IDX(i,j)] = 0.0;
else
cost[IDX(i,j)] = -1.0/*Inf*/;
}
else if (j == i)
// some words don't fit in a line at all -> cost 0.0
cost[IDX(i,j)] = (ct < 0) ? 0.0 : pow((double)ct, exponent_val);
else
cost[IDX(i,j)] = (ct < 0) ? -1.0/*"Inf"*/ : pow((double)ct, exponent_val);
}
}
vector<double> f(nwords); // f[j] == total cost of (optimally) printing words 0..j
vector<bool> where(nwords*nwords, false); // where[IDX(i,j)] == false iff
// we don't wrap after i-th word, i<=j
// when (optimally) printing words 0..j
for (int j=0; j<nwords; ++j) {
if (cost[IDX(0,j)] >= 0.0) {
// no breaking needed: words 0..j fit in one line
f[j] = cost[IDX(0,j)];
continue;
}
// let i = optimal way of printing of words 0..i + printing i+1..j
int i = 0;
while (i <= j) {
if (cost[IDX(i+1,j)] >= 0.0) break;
++i;
}
double best_i = f[i] + cost[IDX(i+1,j)];
for (int k=i+1; k<j; ++k) {
if (cost[IDX(k+1,j)] < 0.0) continue;
double best_cur = f[k] + cost[IDX(k+1,j)];
if (best_cur < best_i) {
best_i = best_cur;
i = k;
}
}
for (int k=0; k<i; ++k)
where[IDX(k,j)] = where[IDX(k,i)];
where[IDX(i,j)] = true;
f[j] = best_i;
}
//.........这里部分代码省略.........
示例9:
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*******************************************************************************/
#include <stdlib.h>
#include <AL/alut.h>
#include <stdio.h>
#include <deque>
#include <string>
#include <sstream>
#include <time.h>
#include <math.h>
#include <iostream>
#include <typeinfo>
#include <deque>
std::deque<int> state;
typename std::deque<int>::iterator it = state.begin();
#include "../include/genetic_process.h"
#include <time.h>
//up to 1/(2^4) second beat resolution
//so for each note, we can hold it 1, 1/2, 1/4, 1/8, or 1/16 beat
// (ie 5 combinations)
#define duration_resolution 5
// assume we're running 1 measure per second
// 4 beats per measure
// then we have 4*16 potential beat-start combinations
// #define num_beats 4 * 16
ALuint sound_source_;
示例10: getOpndList
void Mips16TargetLowering::
getOpndList(SmallVectorImpl<SDValue> &Ops,
std::deque< std::pair<unsigned, SDValue> > &RegsToPass,
bool IsPICCall, bool GlobalOrExternal, bool InternalLinkage,
CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const {
SelectionDAG &DAG = CLI.DAG;
MachineFunction &MF = DAG.getMachineFunction();
MipsFunctionInfo *FuncInfo = MF.getInfo<MipsFunctionInfo>();
const char* Mips16HelperFunction = 0;
bool NeedMips16Helper = false;
if (getTargetMachine().Options.UseSoftFloat &&
Subtarget->inMips16HardFloat()) {
//
// currently we don't have symbols tagged with the mips16 or mips32
// qualifier so we will assume that we don't know what kind it is.
// and generate the helper
//
bool LookupHelper = true;
if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(CLI.Callee)) {
Mips16Libcall Find = { RTLIB::UNKNOWN_LIBCALL, S->getSymbol() };
if (std::binary_search(HardFloatLibCalls, array_endof(HardFloatLibCalls),
Find))
LookupHelper = false;
else {
Mips16IntrinsicHelperType IntrinsicFind = {S->getSymbol(), ""};
// one more look at list of intrinsics
if (std::binary_search(Mips16IntrinsicHelper,
array_endof(Mips16IntrinsicHelper),
IntrinsicFind)) {
const Mips16IntrinsicHelperType *h =(std::find(Mips16IntrinsicHelper,
array_endof(Mips16IntrinsicHelper),
IntrinsicFind));
Mips16HelperFunction = h->Helper;
NeedMips16Helper = true;
LookupHelper = false;
}
}
} else if (GlobalAddressSDNode *G =
dyn_cast<GlobalAddressSDNode>(CLI.Callee)) {
Mips16Libcall Find = { RTLIB::UNKNOWN_LIBCALL,
G->getGlobal()->getName().data() };
if (std::binary_search(HardFloatLibCalls, array_endof(HardFloatLibCalls),
Find))
LookupHelper = false;
}
if (LookupHelper) Mips16HelperFunction =
getMips16HelperFunction(CLI.RetTy, CLI.Args, NeedMips16Helper);
}
SDValue JumpTarget = Callee;
// T9 should contain the address of the callee function if
// -reloction-model=pic or it is an indirect call.
if (IsPICCall || !GlobalOrExternal) {
unsigned V0Reg = Mips::V0;
if (NeedMips16Helper) {
RegsToPass.push_front(std::make_pair(V0Reg, Callee));
JumpTarget = DAG.getExternalSymbol(Mips16HelperFunction, getPointerTy());
ExternalSymbolSDNode *S = cast<ExternalSymbolSDNode>(JumpTarget);
JumpTarget = getAddrGlobal(S, JumpTarget.getValueType(), DAG,
MipsII::MO_GOT, Chain,
FuncInfo->callPtrInfo(S->getSymbol()));
} else
RegsToPass.push_front(std::make_pair((unsigned)Mips::T9, Callee));
}
Ops.push_back(JumpTarget);
MipsTargetLowering::getOpndList(Ops, RegsToPass, IsPICCall, GlobalOrExternal,
InternalLinkage, CLI, Callee, Chain);
}
示例11: EventTriggered
namespace UI {
static View *focusedView;
static bool focusMovementEnabled;
static recursive_mutex mutex_;
const float ITEM_HEIGHT = 64.f;
struct DispatchQueueItem {
Event *e;
EventParams params;
};
std::deque<DispatchQueueItem> g_dispatchQueue;
void EventTriggered(Event *e, EventParams params) {
lock_guard guard(mutex_);
DispatchQueueItem item;
item.e = e;
item.params = params;
g_dispatchQueue.push_front(item);
}
void DispatchEvents() {
lock_guard guard(mutex_);
while (!g_dispatchQueue.empty()) {
DispatchQueueItem item = g_dispatchQueue.back();
g_dispatchQueue.pop_back();
if (item.e) {
item.e->Dispatch(item.params);
}
}
}
void RemoveQueuedEvents(View *v) {
for (size_t i = 0; i < g_dispatchQueue.size(); i++) {
if (g_dispatchQueue[i].params.v == v)
g_dispatchQueue.erase(g_dispatchQueue.begin() + i);
}
}
View *GetFocusedView() {
return focusedView;
}
void SetFocusedView(View *view) {
if (focusedView) {
focusedView->FocusChanged(FF_LOSTFOCUS);
}
focusedView = view;
if (focusedView) {
focusedView->FocusChanged(FF_GOTFOCUS);
}
}
void EnableFocusMovement(bool enable) {
focusMovementEnabled = enable;
if (!enable)
focusedView = 0;
}
bool IsFocusMovementEnabled() {
return focusMovementEnabled;
}
void MeasureBySpec(Size sz, float contentWidth, MeasureSpec spec, float *measured) {
*measured = sz;
if (sz == WRAP_CONTENT) {
if (spec.type == UNSPECIFIED || spec.type == AT_MOST)
*measured = contentWidth;
else if (spec.type == EXACTLY)
*measured = spec.size;
} else if (sz == FILL_PARENT) {
if (spec.type == UNSPECIFIED)
*measured = contentWidth; // We have no value to set
else
*measured = spec.size;
} else if (spec.type == EXACTLY || (spec.type == AT_MOST && *measured > spec.size)) {
*measured = spec.size;
}
}
void Event::Add(std::function<EventReturn(EventParams&)> func) {
HandlerRegistration reg;
reg.func = func;
handlers_.push_back(reg);
}
// Call this from input thread or whatever, it doesn't matter
void Event::Trigger(EventParams &e) {
EventTriggered(this, e);
}
// Call this from UI thread
EventReturn Event::Dispatch(EventParams &e) {
//.........这里部分代码省略.........
示例12:
event_context::event_context()
{
event_contexts.emplace_back();
}
示例13: focus_handler
void focus_handler(const sdl_handler* ptr)
{
if(event_contexts.empty() == false) {
event_contexts.back().set_focus(ptr);
}
}
示例14: lookahead_front
static wint_t lookahead_front(void) { return lookahead_list.front(); }
示例15: backtrace_fake_clear_all
void backtrace_fake_clear_all() {
g_fake_backtrace.clear();
}