All Downloads are FREE. Search and download functionalities are using the official Maven repository.

z3-z3-4.12.6.src.math.lp.incremental_vector.h Maven / Gradle / Ivy

There is a newer version: 4.13.0.1
Show newest version
/*++
Copyright (c) 2017 Microsoft Corporation

Module Name:

    

Abstract:

    

Author:

    Lev Nachmanson (levnach)

Revision History:


--*/

#pragma once
#include "util/vector.h"
namespace lp {
template  class incremental_vector {
    vector m_stack_of_vector_sizes;
    vector m_vector;
public:
    const B & operator[](unsigned a) const {
        return m_vector[a];
    }

    unsigned size() const {
        return m_vector.size();
    }
    
    void push_scope() {
        m_stack_of_vector_sizes.push_back(m_vector.size());
    }

    void pop_scope() {
        pop_scope(1);
    }

    template   
    void pop_tail(vector & v, unsigned k) {
        lp_assert(v.size() >= k);
        v.shrink(v.size() - k);
    }

    template   
    void resize(vector & v, unsigned new_size) {
        v.resize(new_size);
    }

    void pop_scope(unsigned k) {
        lp_assert(m_stack_of_vector_sizes.size() >= k);
        lp_assert(k > 0);
        m_vector.shrink(peek_size(k));
        unsigned new_st_size = m_stack_of_vector_sizes.size() - k;
        m_stack_of_vector_sizes.shrink(new_st_size);
    }

    void push_back(const B & b) {
        m_vector.push_back(b);
    }

    unsigned peek_size(unsigned k) const {
        lp_assert(k > 0 && k <= m_stack_of_vector_sizes.size());
        return m_stack_of_vector_sizes[m_stack_of_vector_sizes.size() - k];
    }
};
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy