ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
provsql::ProbCache Class Reference

The cache of compiled d-DNNFs of one backend. More...

#include "ProbCache.h"

Collaboration diagram for provsql::ProbCache:

Classes

struct  Entry
 A compiled d-DNNF and how its inputs match the leaves of its form. More...

Public Member Functions

const Entry * find (const CanonicalForm &key, const std::string &builder=std::string())
 Looks key up.
bool admits (size_t bytes)
 Whether an entry of bytes is small enough to be stored; counts a rejection otherwise.
bool insert (const CanonicalForm &key, Entry entry)
 Stores entry under key, replacing an entry already there.
void trim ()
 Drops the least recently used entries until the cache fits its budget (which the setting may have lowered since the last insertion).
void reset ()
 Empties the cache and its counters.
ProbCacheStats stats () const
 The counters, with the current number and size of entries.

Static Public Member Functions

static ProbCache & instance ()
 The cache of this backend.

Private Member Functions

 ProbCache ()=default

Private Attributes

std::list< Entry > lru_
std::unordered_map< std::string, std::list< Entry >::iterator > map_
size_t bytes_ = 0
ProbCacheStats stats_

Detailed Description

The cache of compiled d-DNNFs of one backend.

Entries are dropped least recently used first once their estimated total size passes the budget, and a d-DNNF larger than a quarter of the budget is not stored. The budget is provsql.prob_cache_size, lowered to a quarter of provsql.max_memory when that is smaller.

Definition at line 57 of file ProbCache.h.

Constructor & Destructor Documentation

◆ ProbCache()

provsql::ProbCache::ProbCache ( )
privatedefault
Here is the caller graph for this function:

Member Function Documentation

◆ admits()

bool provsql::ProbCache::admits ( size_t bytes)

Whether an entry of bytes is small enough to be stored; counts a rejection otherwise.

Definition at line 180 of file ProbCache.cpp.

◆ find()

const ProbCache::Entry * provsql::ProbCache::find ( const CanonicalForm & key,
const std::string & builder = std::string() )

Looks key up.

A non-empty builder restricts the hit to an entry compiled by that method; an entry of another builder counts as a miss.

Definition at line 166 of file ProbCache.cpp.

◆ insert()

bool provsql::ProbCache::insert ( const CanonicalForm & key,
Entry entry )

Stores entry under key, replacing an entry already there.

Definition at line 188 of file ProbCache.cpp.

Here is the call graph for this function:

◆ instance()

ProbCache & provsql::ProbCache::instance ( )
static

The cache of this backend.

Definition at line 160 of file ProbCache.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

void provsql::ProbCache::reset ( )

Empties the cache and its counters.

Definition at line 214 of file ProbCache.cpp.

Here is the caller graph for this function:

◆ stats()

ProbCacheStats provsql::ProbCache::stats ( ) const

The counters, with the current number and size of entries.

Definition at line 222 of file ProbCache.cpp.

Here is the caller graph for this function:

◆ trim()

void provsql::ProbCache::trim ( )

Drops the least recently used entries until the cache fits its budget (which the setting may have lowered since the last insertion).

Definition at line 204 of file ProbCache.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ bytes_

size_t provsql::ProbCache::bytes_ = 0
private

Definition at line 100 of file ProbCache.h.

◆ lru_

std::list<Entry> provsql::ProbCache::lru_
private

Definition at line 98 of file ProbCache.h.

◆ map_

std::unordered_map<std::string, std::list<Entry>::iterator> provsql::ProbCache::map_
private

Definition at line 99 of file ProbCache.h.

◆ stats_

ProbCacheStats provsql::ProbCache::stats_
mutableprivate

Definition at line 101 of file ProbCache.h.


The documentation for this class was generated from the following files: