1 /** 2 * Copyright 2015, SRI International. 3 * 4 * This file is part of LibPoly. 5 * 6 * LibPoly is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * LibPoly is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with LibPoly. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #pragma once 21 22 #include "poly.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /** 29 * A list of variable that keeps an index for each variable. We don't expect 30 * too many variables in the database, so we keep a map as an array. 31 */ 32 struct lp_variable_list_struct { 33 /** List of variables in the order */ 34 lp_variable_t *list; 35 /** Size of the list */ 36 size_t list_size; 37 /** Capacity of the list */ 38 size_t list_capacity; 39 /** Map from variables to the index in the list (-1 if not in the order) */ 40 int* var_to_index_map; 41 /** Size of the variable map */ 42 size_t var_to_index_map_capacity; 43 }; 44 45 /** Construct a new variable order */ 46 void lp_variable_list_construct(lp_variable_list_t* list); 47 48 /** Destruct the variable order */ 49 void lp_variable_list_destruct(lp_variable_list_t* list); 50 51 /** Get the size of the list */ 52 size_t lp_variable_list_size(const lp_variable_list_t* list); 53 54 /** Get the index of the variable in the list, or -1 if not there */ 55 int lp_variable_list_index(const lp_variable_list_t* list, lp_variable_t x); 56 57 /** Copy the variables into the given vector */ 58 void lp_variable_list_copy_into(const lp_variable_list_t* list, lp_variable_t* vars); 59 60 /** Push a variable to the list */ 61 void lp_variable_list_push(lp_variable_list_t* list, lp_variable_t var); 62 63 /** Pop the last variable from the list */ 64 void lp_variable_list_pop(lp_variable_list_t* list); 65 66 /** Get the last variable from the list */ 67 lp_variable_t lp_variable_list_top(const lp_variable_list_t* list); 68 69 /** Returns 1 if the list contains the given variable */ 70 int lp_variable_list_contains(const lp_variable_list_t* list, lp_variable_t x); 71 72 /** Removes a variable from the list, i.e. replace with lp_variable_null */ 73 void lp_variable_list_remove(lp_variable_list_t* list, lp_variable_t x); 74 75 /** Order the list based on the given order */ 76 void lp_variable_list_order(lp_variable_list_t* list, const lp_variable_order_t* order); 77 78 #ifdef __cplusplus 79 } /* close extern "C" { */ 80 #endif 81