Sha256: af09d614e0efb14932d67b646750fa2a7c918d6a23db47fbac49a441d81b6c4b

Contents?: true

Size: 1.87 KB

Versions: 3

Compression:

Stored size: 1.87 KB

Contents

#ifndef LIMONP_BOUNDED_QUEUE_HPP
#define LIMONP_BOUNDED_QUEUE_HPP

#include <vector>
#include <fstream>
#include <cassert>

namespace Limonp
{
    using namespace std;
    template<class T>
        class BoundedQueue
        {
            private:
                size_t head_;
                size_t tail_;
                size_t size_;
                const size_t capacity_;
                vector<T> circular__buffer;
            public:
                explicit BoundedQueue(size_t capacity): capacity_(capacity), circular__buffer(capacity)
                {
                    head_ = 0;
                    tail_ = 0;
                    size_ = 0;
                    assert(capacity_);
                }
                ~BoundedQueue(){}
            public:
                void clear()
                {
                    head_ = 0;
                    tail_ = 0;
                    size_ = 0;
                }
                bool empty() const
                {
                    return !size_;
                }
                bool full() const
                {
                    return capacity_ == size_;
                }
                size_t size() const
                {
                    return size_;
                }
                size_t capacity() const
                {
                    return capacity_;
                }

                void push(const T& t)
                {
                    assert(!full());
                    circular__buffer[tail_] = t;
                    tail_ = (tail_ + 1) % capacity_;
                    size_ ++;
                }

                T pop()
                {
                    assert(!empty());
                    size_t oldPos = head_;
                    head_ = (head_ + 1) % capacity_;
                    size_ --;
                    return circular__buffer[oldPos];
                }

        };
}

#endif

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jieba_rb-0.0.5 ext/cppjieba/src/Limonp/BoundedQueue.hpp
jieba_rb-0.0.2 ext/cppjieba/src/Limonp/BoundedQueue.hpp
jieba_rb-0.0.1 ext/cppjieba/src/Limonp/BoundedQueue.hpp