
org.logicng.knowledgecompilation.bdds.jbuddy.BDDCache Maven / Gradle / Ivy
///////////////////////////////////////////////////////////////////////////
// __ _ _ ________ //
// / / ____ ____ _(_)____/ | / / ____/ //
// / / / __ \/ __ `/ / ___/ |/ / / __ //
// / /___/ /_/ / /_/ / / /__/ /| / /_/ / //
// /_____/\____/\__, /_/\___/_/ |_/\____/ //
// /____/ //
// //
// The Next Generation Logic Library //
// //
///////////////////////////////////////////////////////////////////////////
// //
// Copyright 2015-20xx Christoph Zengler //
// //
// Licensed under the Apache License, Version 2.0 (the "License"); //
// you may not use this file except in compliance with the License. //
// You may obtain a copy of the License at //
// //
// http://www.apache.org/licenses/LICENSE-2.0 //
// //
// Unless required by applicable law or agreed to in writing, software //
// distributed under the License is distributed on an "AS IS" BASIS, //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or //
// implied. See the License for the specific language governing //
// permissions and limitations under the License. //
// //
///////////////////////////////////////////////////////////////////////////
/*========================================================================
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
All rights reserved
Permission is hereby granted, without written agreement and without
license or royalty fees, to use, reproduce, prepare derivative
works, distribute, and display this software and its documentation
for any purpose, provided that (1) the above copyright notice and
the following two paragraphs appear in all copies of the source code
and (2) redistributions, including without limitation binaries,
reproduce these notices in the supporting documentation. Substantial
modifications to this software may be copyrighted by their authors
and need not follow the licensing terms described here, provided
that the new terms are clearly indicated in all files where they apply.
IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
MODIFICATIONS.
========================================================================*/
package org.logicng.knowledgecompilation.bdds.jbuddy;
/**
* BDD Cache.
* @version 2.0.0
* @since 1.4.0
*/
public class BDDCache {
private final BDDPrime prime;
protected BDDCacheEntry[] table;
/**
* Constructs a new BDD cache of a given size (number of entries in the cache).
* @param cs the cache size
*/
protected BDDCache(final int cs) {
this.prime = new BDDPrime();
resize(cs);
}
/**
* Resizes the cache to a new number of entries. The old cache entries are removed in this process.
* @param ns the new number of entries
*/
protected void resize(final int ns) {
final int size = prime.primeGTE(ns);
this.table = new BDDCacheEntry[size];
for (int n = 0; n < size; n++) {
this.table[n] = new BDDCacheEntry();
}
}
/**
* Resets (clears) the cache.
*/
protected void reset() {
for (final BDDCacheEntry ce : this.table) {
ce.reset();
}
}
/**
* Looks up a given hash value in the cache and returns the respective cache entry.
*
* The return value is guaranteed to be non-null since every entry in the cache is always a {@link BDDCacheEntry}
* object.
* @param hash the hash value.
* @return the respective entry in the cache
*/
protected BDDCacheEntry lookup(final int hash) {
return this.table[Math.abs(hash % this.table.length)];
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy