Source

z3 / src / util / numeral_buffer.h

/*++
Copyright (c) 2011 Microsoft Corporation

Module Name:

    numeral_buffer.h

Abstract:

    Basic buffer for managing big nums.

Author:

    Leonardo de Moura (leonardo) 2011-06-18.

Revision History:

--*/
#ifndef _NUMERAL_BUFFER_H_
#define _NUMERAL_BUFFER_H_

#include"vector.h"

template<typename Numeral, typename NumeralManager>
class numeral_buffer {
    NumeralManager &  m_manager;
    svector<Numeral>  m_buffer;
public:
    typedef Numeral numeral;
    typedef Numeral data;
    typedef NumeralManager manager;

    numeral_buffer(NumeralManager & m):m_manager(m) {}

    ~numeral_buffer() {
        reset();
    }
    
    NumeralManager & m() const { return m_manager; }

    unsigned size() const { return m_buffer.size(); }
    
    bool empty() const { return m_buffer.empty(); }

    void push_back(Numeral const & num) {
        m_buffer.push_back(Numeral());
        m().set(m_buffer.back(), num);
    }
    
    void pop_back() {
        m().del(m_buffer.back());
        m_buffer.pop_back();
    }

    Numeral & back() {
        return m_buffer.back();
    }

    Numeral const & back() const {
        return m_buffer.back();
    }
    
    Numeral const & operator[](unsigned idx) const {
        return m_buffer[idx];
    }

    Numeral & operator[](unsigned idx) {
        return m_buffer[idx];
    }

    void reset() {
        typename vector<Numeral>::iterator it  = m_buffer.begin();
        typename vector<Numeral>::iterator end = m_buffer.end();
        for (; it != end; ++it)
            m().del(*it);
        m_buffer.reset();
    }

    Numeral * c_ptr() { return m_buffer.c_ptr(); }

    void reserve(unsigned sz) {
        m_buffer.reserve(sz);
    }

    void swap(svector<Numeral> & other) {
        m_buffer.swap(other);
    }

};

#endif
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.