strspace.cpp revision c98fb3e16fcd571a790eab772c0c66173d225205
/* $Id$ */
/** @file
* innotek Portable Runtime - Unique String Spaces.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/*
* AVL configuration.
*/
#define KAVL_FN(a) rtstrspace##a
#define KAVL_EQUAL_ALLOWED 1
#define KAVLNODECORE RTSTRSPACECORE
#define PKAVLNODECORE PRTSTRSPACECORE
#define PPKAVLNODECORE PPRTSTRSPACECORE
#define PKAVLCALLBACK PFNRTSTRSPACECALLBACK
/*
* AVL Compare macros
*/
/*
* Include the code.
*/
#include "table/avl_Base.cpp.h"
#include "table/avl_Get.cpp.h"
#include "table/avl_DoWithAll.cpp.h"
#include "table/avl_Destroy.cpp.h"
/* sdbm:
This algorithm was created for sdbm (a public-domain reimplementation of
ndbm) database library. it was found to do well in scrambling bits,
causing better distribution of the keys and fewer splits. it also happens
to be a good general hashing function with good distribution. the actual
function is hash(i) = hash(i - 1) * 65599 + str[i]; what is included below
is the faster version used in gawk. [there is even a faster, duff-device
version] the magic constant 65599 was picked out of thin air while
experimenting with different constants, and turns out to be a prime.
this is one of the algorithms used in berkeley db (see sleepycat) and
elsewhere. */
{
int c;
while ((c = *pu8++))
return hash;
}
/**
* Inserts a string into a unique string space.
*
* @returns true on success.
* @returns false if the string collieded with an existing string.
* @param pStrSpace The space to insert it into.
* @param pStr The string node.
*/
{
if (!pMatch)
/* Check for clashes. */
return false;
return false;
}
/**
* Removes a string from a unique string space.
*
* @returns Pointer to the removed string node.
* @returns NULL if the string was not found in the string space.
* @param pStrSpace The space to insert it into.
* @param pszString The string to remove.
*/
{
if (!pCur)
return NULL;
/* find the right one. */
break;
if (pCur)
{
if (pPrev)
/* simple, it's in the linked list. */
else
{
/* in the tree. remove and reinsert list head. */
if (pInsert)
{
}
}
}
return pCur;
}
/**
* Gets a string from a unique string space.
*
* @returns Pointer to the string node.
* @returns NULL if the string was not found in the string space.
* @param pStrSpace The space to insert it into.
* @param pszString The string to get.
*/
{
if (!pCur)
return NULL;
/* Linear search. */
return pCur;
return NULL;
}
/**
* Enumerates the string space.
* The caller supplies a callback which will be called for each of
* the string nodes.
*
* @returns 0 or what ever non-zero return value pfnCallback returned
* when aborting the destruction.
* @param pStrSpace The space to insert it into.
* @param pfnCallback The callback.
* @param pvUser The user argument.
*/
RTDECL(int) RTStrSpaceEnumerate(PRTSTRSPACE pStrSpace, PFNRTSTRSPACECALLBACK pfnCallback, void *pvUser)
{
}
/**
* Destroys the string space.
* The caller supplies a callback which will be called for each of
* the string nodes in for freeing their memory and other resources.
*
* @returns 0 or what ever non-zero return value pfnCallback returned
* when aborting the destruction.
* @param pStrSpace The space to insert it into.
* @param pfnCallback The callback.
* @param pvUser The user argument.
*/
RTDECL(int) RTStrSpaceDestroy(PRTSTRSPACE pStrSpace, PFNRTSTRSPACECALLBACK pfnCallback, void *pvUser)
{
}