/* * Thread safe queue operation for deleting an entry to the TopicList using the key (mutex) * Lock the TopicList * Circular buffer, check that the queue is not empty. * A subscriber has read the entry, increase TopicNode readcount and increase the reader index * If every subscriber has read the entry then add the node to the archiver. * Unlock the TopicList */ bool dequeue(TopicList &topicList, std::string &data, size_t &readerIndex) { bool success = false; int lockResult = pthread_mutex_lock(&topicList.mutex); assert(lockResult == 0); if (readerIndex != topicList.writeIndex) { TopicNode &node = topicList.circularBuffer[readerIndex]; node.readCount++; data = node.data; readerIndex = succ(readerIndex); success = true; // Retrieved the node successfully if (node.readCount == topicList.totalSubscribers) { addToArchive(topicList, &node); // Every subscriber has read the node, archive the node. topicList.readIndex = succ(topicList.readIndex); } } pthread_mutex_unlock(&topicList.mutex); //fprintf(stderr, "dequeue result: %d\n", success); return success; }
void split_paths( const filesystem::path& p1, const filesystem::path& p2, filesystem::path& common, filesystem::path& r1, filesystem::path& r2) { assert(common.empty()); assert(r1.empty()); assert(r2.empty()); filesystem::path::const_iterator i1 = p1.begin(); filesystem::path::const_iterator i2 = p2.begin(); while (i1 != p1.end() && i2 != p2.end()) { if (*i1 != *i2) break; if ((p1.has_filename() && succ(i1) == p1.end()) || (p2.has_filename() && succ(i2) == p2.end())) break; common /= *i1; ++i1, ++i2; } while (i1 != p1.end()) r1 /= *i1++; while (i2 != p2.end()) r2 /= *i2++; }
int succ(node * t, int x , int curr_max) { if( t->val <= x ) { if ( t->val== x && t->right==NULL ) if (curr_max) return curr_max; else return t->val; //x = max if (t->right!=NULL ) return succ(t->right, x, curr_max); //go right child else if (!curr_max) return NULL; else return curr_max; //x larger than any in tree } else { if (t->left!=NULL ) { if( curr_max > t->val && t->val < x) return curr_max; curr_max = t->val; return succ(t->left, x, curr_max); } else if ( curr_max < t->val ) return curr_max; else return t->val; } }
/** * Paint edge */ void GuiEdge::paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { if ( succ() == 0 || pred() == 0)//!!! What is the ugliness! { out ("ERROR: the deleted edge is tried to paint!"); return; } if (!edge_valid_priv) return; edgeApplStyle (painter, option); qreal arrowSize = 10; // painter->setPen( QPen( Qt::darkRed, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); GuiNode* suc = addGui ( succ()); GuiNode* pre = addGui ( pred()); if (isVirtualRootEdge() && !addGui (graph)->showVnodes()) return;//Do not show virtual root edges if( suc->real()) { QPointF dir = (7*edge_end_dir_priv + edge_start_point_priv)/8 - edge_end_point_priv;//!!! Mnemonic rule, it must be changed drawLineHead (painter, edge_end_point_priv, -atan2 (dir.y(), dir.x()), 10, false); } if (edgeLabel().size() && addGui (graph)->showEdgeLabels()) { drawText (painter); } painter->setBrush( Qt::transparent);//!!! change it to black, and you will see, what heppend. I can't explain this painter->drawPath (edge_curve_priv); }
static inline void insertListNode(void *bp, size_t index){ char *firstList = heap_listp + DSIZE; put(succ(bp), get(succ(firstList + index * DSIZE))); put(pred(bp), get(pred(nextFree(bp)))); put(succ(firstList + index * DSIZE), (long)bp - (long)heap_listp); put(pred(nextFree(bp)), (long)bp - (long)heap_listp); }
inline id_t succ<id_t>(id_t id) { if (id.x == std::numeric_limits<int64_t>::max()) { if (id.y == std::numeric_limits<int64_t>::max()) throw std::out_of_range("das::id_t overflowed."); return id_t(zero<int64_t>(), succ(id.y)); } return id_t(succ(id.x), id.y); }
void stuffCommand(char *s) { if (succ(historyHead) == historyTail) { if (historyList[historyTail]) release(historyList[historyTail]); historyTail = succ(historyTail); } historyList[historyHead] = newStringId(s,"history"); historyHead = succ(historyHead); historyLast = historyHead; }
/** * Print edge in DOT format to stdout */ void Edge::debugPrint() { /** * Check that edge is printable * TODO: Implements graph states and in 'in process' state print node as '?' * Examples of such prints: 4->? ?->3 ?->? */ assert( isNotNullP( pred())); assert( isNotNullP( succ())); out("%llu->%llu;", pred()->id(), succ()->id()); }
void add_arc(t_graph g, int s, int d, float c) { t_adj pa; pa = malloc(sizeof(struct s_adj)); pa->cost = c; pa->vsom = d; pa->next = succ(g,s); succ(g,s) = pa; pa = malloc(sizeof(struct s_adj)); pa->cost = c; pa->vsom = s; pa->next = pred(g,d); pred(g,d) = pa; }
void DepCompCopyArrayToBuffer:: EnforceCopyRoot( DepCompCopyArrayCollect::CopyArrayUnit& curunit, const DepCompAstRefGraphCreate& refDep, const DepCompAstRefGraphNode* outnode, DepCompCopyArrayCollect::CopyArrayUnit::NodeSet& cuts) { int copylevel = curunit.copylevel(); DepCompCopyArrayCollect::CopyArrayUnit::CrossGraphOut crossout(&refDep, curunit); GraphNodePredecessorIterator<DepCompCopyArrayCollect::CopyArrayUnit::CrossGraphOut> preds(&crossout, outnode); bool complete = EnforceCopyRootRemove(preds, outnode, copylevel, cuts); DepCompCopyArrayCollect::CopyArrayUnit tmp = curunit; tmp.refs -= cuts; DepCompCopyArrayCollect::CopyArrayUnit::CrossGraphIn crossin(&refDep, tmp); GraphNodeSuccessorIterator<DepCompCopyArrayCollect::CopyArrayUnit::CrossGraphIn> succ(&crossin, outnode); if (!EnforceCopyRootRemove( succ, outnode, copylevel, cuts)) complete = false; if (complete) return; tmp.refs -= cuts; EnforceCopyRootRemove(tmp.refs.begin(), outnode, copylevel, cuts); }
void PriorityQueue<Item, IDPolicy>::moveDownPos(Index position) { const Index index(this->heap[position]); const Index size(getSize()); Index succ(2*position+1); Index pos(position); while(succ < size) { const Index rightPos(succ + 1); if(rightPos < size && (this->itemVector[this->heap[rightPos]]->getTime() < this->itemVector[this->heap[succ]]->getTime() || (this->itemVector[this->heap[rightPos]]->getTime() == this->itemVector[this->heap[succ]]->getTime() && this->itemVector[this->heap[rightPos]]->getPriority() > this->itemVector[this->heap[succ]]->getPriority()))) { succ = rightPos; } this->heap[pos] = this->heap[succ]; this->positionVector[this->heap[pos]] = pos; pos = succ; succ = 2*pos+1; } this->heap[pos] = index; this->positionVector[index] = pos; moveUpPos(pos, position); }
/** * Principal function. It creates Nodes and Edges to put in the Graph, * from the given BBHG * @param bhg source BBHG */ void BBHGDrawer::make() { if(_made) { return; } ASSERT(_bhg); ASSERT(_graph); // Construct the Graph HashTable<void*, display::Node*> map; for(BBHG::Iterator bb(_bhg); bb; bb++) { display::Node *node = _graph->newNode(); map.put(*bb, node); onNode(*bb, node); } for(BBHG::Iterator bb(_bhg); bb; bb++) { display::Node *node = map.get(*bb); for(BBHG::OutIterator succ(bb); succ; succ++) { BBHGEdge* edge = succ; display::Edge *display_edge; display_edge = _graph->newEdge(node,map.get(edge->target())); onEdge(edge, display_edge); } } onEnd(_graph); _made = true; }
/* * Thread safe queue operation for adding an entry to the TopicList using the key (mutex) * Lock the TopicList * Circular buffer, check for !full using helper function. * Create a node with the current time, the ID of the publisher, and data entry * Unlock the TopicList */ bool enqueue(TopicList &topicList, int publisherID, const char *data) { bool success = false; int lockResult = pthread_mutex_lock(&topicList.mutex); assert(lockResult == 0); if (!isFull(topicList)) { TopicNode &node = topicList.circularBuffer[topicList.writeIndex]; time_t timev; time(&timev); node.timeStamp = timev; node.pubID = publisherID; node.readCount = 0; size_t size = sizeof(node.data); strlcpy(node.data, data, size); topicList.writeIndex = succ(topicList.writeIndex); success = true; } pthread_mutex_unlock(&topicList.mutex); //fprintf(stderr, "enqueue result: %d\n", success); return success; }
tree *delete_tree(tree *t, int k) { tree * x = Descend(t, k); if (x == NULL) printf("lol1\n"); if (x->left == NULL && x->right == NULL) t = ReplaceNode(t, x, NULL); else if (x->left == NULL) t = ReplaceNode(t, x, x->right); else if (x->right == NULL) t = ReplaceNode(t, x, x->left); else { tree * y = succ(x); t = ReplaceNode(t, y, y->right); x->left->parent = y; y->left = x->left; if (x->right != NULL) x->right->parent = y; y->right = x->right; t = ReplaceNode(t, x, y); //y->count = x->count; } free(x->word); free(x); return t; }
void bt() { int hs, is; stack[1] = start_node; level = 2; init(); while(level > 0) { hs = 1; is = 0; while(hs && !is) { hs = succ(); if(hs) is = valid(); } if(hs) { if(sol()) print(); else {level++;init();} } else level--; } };
RNode * succ(RBT * T ,RNode * x) { if(x == T->nil) return x; RNode * ret = T->nil; ret = succ(T,x->L); if(ret == T->nil) ret = x; return ret; }
type dequeue(Queue Q) { int i; Q->size--; i=Q->front; Q->front=succ(Q->front,Q); return Q->array[i]; }
char *nextCommand() { if (historyLast == historyHead) return(NULL); else { historyLast = succ(historyLast); return(historyList[historyLast]); } }
Type succ(int &root , Type key) { if (root == 0) { return key; } else if (K[root] > key) { Type ret = succ(LC[root] , key); if (ret == key) return K[root]; return ret; } else { return succ(RC[root] , key); } }
static size_t MOD(size_t i, size_t n) { #if 1 return succ(i, n); #else return ((i) % (n) > 0 ? (i) % (n) : (i) % (n) + (n)); #endif }
/* * dequeue, but we don't return that element */ void dequeue(queue q) { if(is_empty(q)) { fprintf(stderr, "dequeue: the queue is empty\n"); exit(-1); } q->front = succ(q, q->front); }
void Collect(SLCell r[],ArrType f,ArrType e) { /* 本算法按keys[i]自小至大地将f[0..RADIX-1]所指各子表依次链接成 */ /* 一个链表,e[0..RADIX-1]为各子表的尾指针。算法10.16 */ int j,t; for(j=0;!f[j];j=succ(j)); /* 找第一个非空子表,succ为求后继函数 */ r[0].next=f[j]; t=e[j]; /* r[0].next指向第一个非空子表中第一个结点 */ while(j<RADIX-1) { for(j=succ(j);j<RADIX-1&&!f[j];j=succ(j)); /* 找下一个非空子表 */ if(f[j]) { /* 链接两个非空子表 */ r[t].next=f[j]; t=e[j]; } } r[t].next=0; /* t指向最后一个非空子表中的最后一个结点 */ }
bool pop_front() { if ( len > 0 ) { len--; succ(head); return true; } return false; }
int main(int argc, char* argv) { int keinPointer = 5; int* pointer = &keinPointer; std::cout << wrongSucc(keinPointer) << std::endl; std::cout << wrongSucc(pointer) << std::endl; std::cout << succ(pointer) << std::endl; std::cout << succ(keinPointer) << std::endl; std::cout << "Hello World" << std::endl; std::cout << _NumericLimits<int>::Max << std::endl; std::cout << _NumericLimits<int>::Min << std::endl; system("PAUSE"); }
namespace boost { namespace hana { namespace test { template <typename E> auto laws<Enumerable, E> = [] { static_assert(models<Enumerable(E)>{}, ""); for_each(objects<E>, [](auto x) { BOOST_HANA_CHECK(equal( succ(pred(x)), x )); BOOST_HANA_CHECK(equal( pred(succ(x)), x )); }); }; }}} // end namespace boost::hana::test
static void Collect(SLCell r[],ArrType f,ArrType e) { // 本算法按keys[i]自小至大地将f[0..RADIX-1]所指各子表依次链接成 // 一个链表,e[0..RADIX-1]为各子表的尾指针。算法10.16 int j,t; for(j=0;!f[j];j=succ(j)); // 找第一个非空子表,succ为求后继函数 r[0].next=f[j]; t=e[j]; // r[0].next指向第一个非空子表中第一个结点 while(j<RADIX-1) { for(j=succ(j);j<RADIX-1&&!f[j];j=succ(j)); // 找下一个非空子表 if(f[j]) { // 链接两个非空子表 r[t].next=f[j]; t=e[j]; } } r[t].next=0; // t指向最后一个非空子表中的最后一个结点 }
void enqueue(element_type x,QUEUE Q) { if(Q->q_max_size==Q->q_size) error("Queue is FULL"); else{ Q->q_size++; Q->q_rear=succ(Q->q_rear,Q); Q->q_array[Q->q_rear]=x; } }
QVariant EdgeItem::itemChange( GraphicsItemChange change, const QVariant &value) { if ( change == QGraphicsItem::ItemSelectedChange) { pred()->item()->update(); succ()->item()->update(); } return QGraphicsItem::itemChange( change, value); }
obj dequeue_pop_front( obj deq ) { obj item, newf, oldf = DEQ_FRONT(deq); assert_ne(deq, "dequeue-pop-front!"); newf = succ( deq, oldf ); SET_DEQ_FRONT( deq, newf ); item = gvec_ref( DEQ_STATE(deq), FXWORDS_TO_RIBYTES(oldf) ); gvec_write_non_ptr( DEQ_STATE(deq), FXWORDS_TO_RIBYTES(oldf), FALSE_OBJ ); return item; }
/** * @brief * @param Q * @param X * * */ void QueueEnqueue(Queue Q, ElementType X) { if (QueueIsFull(Q)) { fprintf(stderr, "Enqueue: queue if full!\n"); exit(1); } Q->rear = succ(Q->rear, Q); Q->array[Q->rear] = X; Q->size++; }