2006-03-31 20:57:31 -04:00
|
|
|
|
/* cache.h - definitions for the LRU cache
|
|
|
|
|
*
|
2008-03-28 17:08:36 -03:00
|
|
|
|
* Copyright (C) 2004-2007 Gerhard H<EFBFBD>ring <gh@ghaering.de>
|
2006-03-31 20:57:31 -04:00
|
|
|
|
*
|
|
|
|
|
* This file is part of pysqlite.
|
|
|
|
|
*
|
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
|
* warranty. In no event will the authors be held liable for any damages
|
|
|
|
|
* arising from the use of this software.
|
|
|
|
|
*
|
|
|
|
|
* Permission is granted to anyone to use this software for any purpose,
|
|
|
|
|
* including commercial applications, and to alter it and redistribute it
|
|
|
|
|
* freely, subject to the following restrictions:
|
|
|
|
|
*
|
|
|
|
|
* 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
|
* claim that you wrote the original software. If you use this software
|
|
|
|
|
* in a product, an acknowledgment in the product documentation would be
|
|
|
|
|
* appreciated but is not required.
|
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
|
* misrepresented as being the original software.
|
|
|
|
|
* 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef PYSQLITE_CACHE_H
|
|
|
|
|
#define PYSQLITE_CACHE_H
|
|
|
|
|
#include "Python.h"
|
|
|
|
|
|
2006-04-23 12:24:26 -03:00
|
|
|
|
/* The LRU cache is implemented as a combination of a doubly-linked with a
|
|
|
|
|
* dictionary. The list items are of type 'Node' and the dictionary has the
|
|
|
|
|
* nodes as values. */
|
|
|
|
|
|
2007-01-13 21:43:50 -04:00
|
|
|
|
typedef struct _pysqlite_Node
|
2006-03-31 20:57:31 -04:00
|
|
|
|
{
|
|
|
|
|
PyObject_HEAD
|
|
|
|
|
PyObject* key;
|
|
|
|
|
PyObject* data;
|
|
|
|
|
long count;
|
2007-01-13 21:43:50 -04:00
|
|
|
|
struct _pysqlite_Node* prev;
|
|
|
|
|
struct _pysqlite_Node* next;
|
|
|
|
|
} pysqlite_Node;
|
2006-03-31 20:57:31 -04:00
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
PyObject_HEAD
|
|
|
|
|
int size;
|
2006-04-23 12:24:26 -03:00
|
|
|
|
|
|
|
|
|
/* a dictionary mapping keys to Node entries */
|
2006-03-31 20:57:31 -04:00
|
|
|
|
PyObject* mapping;
|
2006-04-23 12:24:26 -03:00
|
|
|
|
|
|
|
|
|
/* the factory callable */
|
2006-03-31 20:57:31 -04:00
|
|
|
|
PyObject* factory;
|
2006-04-23 12:24:26 -03:00
|
|
|
|
|
2007-01-13 21:43:50 -04:00
|
|
|
|
pysqlite_Node* first;
|
|
|
|
|
pysqlite_Node* last;
|
2006-04-23 12:24:26 -03:00
|
|
|
|
|
|
|
|
|
/* if set, decrement the factory function when the Cache is deallocated.
|
|
|
|
|
* this is almost always desirable, but not in the pysqlite context */
|
2006-03-31 20:57:31 -04:00
|
|
|
|
int decref_factory;
|
2007-01-13 21:43:50 -04:00
|
|
|
|
} pysqlite_Cache;
|
2006-03-31 20:57:31 -04:00
|
|
|
|
|
2007-01-13 21:43:50 -04:00
|
|
|
|
extern PyTypeObject pysqlite_NodeType;
|
|
|
|
|
extern PyTypeObject pysqlite_CacheType;
|
2006-03-31 20:57:31 -04:00
|
|
|
|
|
2007-01-13 21:43:50 -04:00
|
|
|
|
int pysqlite_node_init(pysqlite_Node* self, PyObject* args, PyObject* kwargs);
|
|
|
|
|
void pysqlite_node_dealloc(pysqlite_Node* self);
|
2006-03-31 20:57:31 -04:00
|
|
|
|
|
2007-01-13 21:43:50 -04:00
|
|
|
|
int pysqlite_cache_init(pysqlite_Cache* self, PyObject* args, PyObject* kwargs);
|
|
|
|
|
void pysqlite_cache_dealloc(pysqlite_Cache* self);
|
|
|
|
|
PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* args);
|
2006-03-31 20:57:31 -04:00
|
|
|
|
|
2007-01-13 21:43:50 -04:00
|
|
|
|
int pysqlite_cache_setup_types(void);
|
2006-03-31 20:57:31 -04:00
|
|
|
|
|
|
|
|
|
#endif
|