キューの典型的な実装 (ノード、カウンター、プッシュ メソッド、およびポップ メソッドを表すリンク リスト) があると仮定すると、キューの到着率と出発率を測定する最良の方法は何でしょうか。リストに新しいアイテム?2 つの別々のスレッドが必要で、1 つの 2 つのスレッドが各レートを測定する必要がありますか?
疑似コード/アイデアは大歓迎です!
(私は答えを助けるためにこれをすぐに書きました。簡単にするためにテンプレートを省略しました)
class my_queue{
public:
struct Node{
Node* next;
Node* previous;
int data;
}
Node* head;
Node* tail;
int queue_size;
my_queue(){}
int pop(){
Node* old_head = head;
Node* new_head = old_head->previous;
new_head->next = null;
head = new_head;
int data = old_head->data
delete old_head;
queue_size--;
return data;
}
void push(int data){
Node* new_tail = new Node();
new_node->data = data;
Node* old_tail = tail;
old_tail->previous = new_tail;
new_node->next = old_tail;
tail = new_tail;
queue_size++;
}
int getSize(){
return queue_size;
}
};