Permalink
Browse files

Implemented simple LRU caching mechanism to avoid reparsing previousl…

…y used SMARTS queries. The cache size is set to 20 by default but can be set by the user

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information...
1 parent b90c252 commit c3a768d356ddd6998901e81d5cccef67ec02f605 @rajarshi rajarshi committed with egonw Jan 21, 2011
Showing with 10 additions and 1 deletion.
  1. +10 −1 src/main/org/openscience/cdk/smiles/smarts/SMARTSQueryTool.java
@@ -120,7 +120,7 @@
private List<List<Integer>> matchingAtoms = null;
// a simplistic cache to store parsed SMARTS queries
- final int MAX_ENTRIES = 20;
+ private int MAX_ENTRIES = 20;
Map<String, QueryAtomContainer> cache = new LinkedHashMap<String, QueryAtomContainer>(MAX_ENTRIES + 1, .75F, true) {
public boolean removeEldestEntry(Map.Entry eldest) {
return size() > MAX_ENTRIES;
@@ -137,6 +137,15 @@ public SMARTSQueryTool(String smarts) throws CDKException {
}
/**
+ * Set the maximum size of the query cache.
+ *
+ * @param maxEntries The maximum number of entries
+ */
+ public void setQueryCacheSize(int maxEntries) {
+ MAX_ENTRIES = maxEntries;
+ }
+
+ /**
* Returns the current SMARTS pattern being used.
*
* @return The SMARTS pattern

0 comments on commit c3a768d

Please sign in to comment.