PolyBoRi
cache_manager.h
Go to the documentation of this file.
1 /* Copyright (c) 2005-2007 by The PolyBoRi Team */
2 
3 #include <polybori.h>
4 #include <algorithm>
5 #include <utility>
6 #include <iostream>
7 #include <boost/shared_ptr.hpp>
8 #include "groebner_defs.h"
9 #ifndef PBORI_GB_CACHE_H
10 #define PBORI_GB_CACHE_H
11 
12 
14 template<class idx_type1, class idx_type2> void set_up_translation_vectors(std::vector<idx_type1>& ring_2_0123, std::vector<idx_type2>& back_2_ring, const Exponent& used_variables){
15  BooleExponent::const_iterator it=used_variables.begin();
16  BooleExponent::const_iterator end=used_variables.end();
17  idx_type1 idx_0123=0;
18  while(it!=end){
19  ring_2_0123[*it]=idx_0123;
20  back_2_ring[idx_0123]=*it;
21  idx_0123++;
22  it++;
23  }
24 }
25 
26 //template<class idx_type1, class idx_type2> void set_up_translation_vectors(std::vector<idx_type1>& ring_2_0123, std::vector<idx_type>& back_2_ring, const Exponent& used_variables);
27 Polynomial translate_indices(const Polynomial& p, const std::vector<idx_type>& table);
29  public:
31 
32  typedef std::vector<Polynomial> poly_vec_type;
33  typedef boost::shared_ptr<poly_vec_type> res_type;
35  protected:
37  public:
39 
40  }
41  res_type lookup(const Polynomial& p, bool& succ){
42  int nv=p.ring().nVariables();
43  BooleExponent used_exp=p.usedVariablesExp();
44  std::vector<idx_type> back_2_ring(used_exp.size());
45  std::vector<idx_type> ring_2_0123(nv);
46 
47  //PBORI_ASSERT(nv<255);
48  set_up_translation_vectors(ring_2_0123,back_2_ring, used_exp);
49  Polynomial p_t=translate_indices(p,ring_2_0123);
50  impl_iterator_type it=impl.find(p_t);
51  //cache_res_type res;
52  if (it!=impl.end()){
53  succ=true;
54  res_type res(new poly_vec_type(it->second));
55 
56 
57  for(poly_vec_type::size_type i=0;i<res->size();i++){
58  (*res)[i]=translate_indices((*res)[i],back_2_ring);
59  }
60  return res;
61  }
62  else{
63  succ=false;
64  return res_type();
65  }
66  }
67  void insert(const Polynomial& key, const poly_vec_type& value){
68  int nv=key.ring().nVariables();
69  BooleExponent used_exp=key.usedVariablesExp();
70  std::vector<idx_type> back_2_ring(used_exp.size());
71  std::vector<idx_type> ring_2_0123(nv);
72  set_up_translation_vectors(ring_2_0123,back_2_ring, used_exp);
73  Polynomial key_t=translate_indices(key,ring_2_0123);
74  poly_vec_type value_t(value);
75 
76  for(poly_vec_type::size_type i=0;i<value_t.size();i++){
77  value_t[i]=translate_indices(value_t[i], ring_2_0123);
78  }
79  impl[key_t]=value_t;
80  }
81 
82 
83 };
85 #endif