/* Copyright (c) 2018
   Charles Jordan (Hokkaido University, Sapporo, Japan),
   Michael Joswig, Lars Kastner (Technische Universitaet Berlin, Germany)

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 3, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
-----------------------------------------------------------------------------
*/

///////////////////////////////////////////////////////////////////////////////
// RegularityCheckCache.hh
// 
// This file contains a cache for the regularity checks. When we walk down a
// flip and then check all the flips of the target triangulations for
// regularity, many of them will already have been previously checked, so a
// cache should be useful.
///////////////////////////////////////////////////////////////////////////////
#ifndef REGULARITYCHECKCACHE_HH
#define REGULARITYCHECKCACHE_HH
#include "mptopcom_typedefs.hh"
#include "TriangNode.hh"
#include "LRUCache.hh"
#include "GKZ.hh"
class RegularityCheckCache {
   private:
      mutable LRUCache<TriangNode, bool> cache;
      const gkz_type& gkz;

   public: 
      RegularityCheckCache(int size, const gkz_type& gkz_in):
          gkz(gkz_in), cache(size){};

      bool isRegular(const TriangNode& t) const{
         bool result;
         if(cache.exist(t)){
            result = cache.get(t);
         } else {
            result = gkz.isRegular(t);
            cache.put(t, result);
         }
         return result;
      }
};

#endif

