2012-09-07 15:33:22 +08:00
|
|
|
#ifndef _RPMSTRPOOL_H
|
|
|
|
#define _RPMSTRPOOL_H
|
|
|
|
|
2014-05-11 08:27:26 +08:00
|
|
|
/** \ingroup rpmstrpool
|
|
|
|
* \file rpmio/rpmstrpool.h
|
|
|
|
*
|
|
|
|
* String pools manipulation helper functions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-09-07 19:09:35 +08:00
|
|
|
#include <rpm/rpmtypes.h>
|
2012-09-07 15:33:22 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-09-27 18:11:03 +08:00
|
|
|
/** \ingroup rpmstrpool
|
|
|
|
* Create a new, empty string pool.
|
|
|
|
* @return new string pool
|
|
|
|
*/
|
2012-09-07 15:33:22 +08:00
|
|
|
rpmstrPool rpmstrPoolCreate(void);
|
|
|
|
|
2012-09-27 18:11:03 +08:00
|
|
|
/** \ingroup rpmstrpool
|
|
|
|
* Free a string pool and its contents. While other references exist,
|
|
|
|
* this only decrements the reference count.
|
|
|
|
* @param pool string pool
|
|
|
|
* @return NULL always
|
|
|
|
*/
|
2012-09-27 17:18:39 +08:00
|
|
|
rpmstrPool rpmstrPoolFree(rpmstrPool pool);
|
2012-09-07 15:33:22 +08:00
|
|
|
|
2012-09-27 18:11:03 +08:00
|
|
|
/** \ingroup rpmstrpool
|
|
|
|
* Reference a string pool
|
|
|
|
* @param pool string pool
|
|
|
|
* @return new string pool reference
|
|
|
|
*/
|
2012-09-27 17:18:39 +08:00
|
|
|
rpmstrPool rpmstrPoolLink(rpmstrPool pool);
|
2012-09-07 15:33:22 +08:00
|
|
|
|
2012-09-27 18:11:03 +08:00
|
|
|
/** \ingroup rpmstrpool
|
|
|
|
* Freeze a string pool: new strings cannot be added to a frozen pool.
|
|
|
|
* If keephash is 0, memory usage is minimized but string -> id lookups
|
|
|
|
* are no longer possible and unfreezing is an expensive operation.
|
|
|
|
* Id -> string lookups are always possible on a frozen pool too.
|
|
|
|
* @param pool string pool
|
|
|
|
* @param keephash should string -> id hash be kept around?
|
|
|
|
*/
|
2012-09-27 17:18:39 +08:00
|
|
|
void rpmstrPoolFreeze(rpmstrPool pool, int keephash);
|
2012-09-07 15:33:22 +08:00
|
|
|
|
2012-09-27 18:11:03 +08:00
|
|
|
/** \ingroup rpmstrpool
|
|
|
|
* Unfreeze a string pool to allow new additions again.
|
|
|
|
* If keephash was not specified on freezing, this requires rehashing
|
|
|
|
* the entire pool contents.
|
|
|
|
* @param pool string pool
|
|
|
|
*/
|
2012-09-27 17:18:39 +08:00
|
|
|
void rpmstrPoolUnfreeze(rpmstrPool pool);
|
2012-09-07 15:33:22 +08:00
|
|
|
|
2012-09-27 18:11:03 +08:00
|
|
|
/** \ingroup rpmstrpool
|
|
|
|
* Look up the id of a string. If create is specified the string is
|
|
|
|
* added to the pool if it does not already exist. Creation can only
|
|
|
|
* fail if the pool is in frozen state.
|
|
|
|
* @param pool string pool
|
|
|
|
* @param s \0-terminated string to look up
|
|
|
|
* @param create should an id be created if not already present?
|
|
|
|
* @return id of the string or 0 for not found
|
|
|
|
*/
|
2012-09-27 17:18:39 +08:00
|
|
|
rpmsid rpmstrPoolId(rpmstrPool pool, const char *s, int create);
|
2012-09-07 15:33:22 +08:00
|
|
|
|
2012-09-27 18:11:03 +08:00
|
|
|
/** \ingroup rpmstrpool
|
|
|
|
* Look up the id of a string with predetermined length. The string does
|
|
|
|
* not have to be \0-terminated. If create is specified the string is
|
|
|
|
* added to the pool if it does not already exist. Creation can only
|
|
|
|
* fail if the pool is in frozen state.
|
|
|
|
* @param pool string pool
|
|
|
|
* @param s string to look up
|
|
|
|
* @param slen number of characters from s to consider
|
|
|
|
* @param create should an id be created if not already present?
|
|
|
|
* @return id of the string or 0 for not found
|
|
|
|
*/
|
2012-09-27 17:18:39 +08:00
|
|
|
rpmsid rpmstrPoolIdn(rpmstrPool pool, const char *s, size_t slen, int create);
|
2012-09-07 15:33:22 +08:00
|
|
|
|
2012-09-27 18:11:03 +08:00
|
|
|
/** \ingroup rpmstrpool
|
|
|
|
* Look up a string by its pool id.
|
|
|
|
* @param pool string pool
|
|
|
|
* @param sid pool id of a string
|
|
|
|
* @return pointer to the string or NULL for invalid id
|
|
|
|
*/
|
2012-09-27 17:18:39 +08:00
|
|
|
const char * rpmstrPoolStr(rpmstrPool pool, rpmsid sid);
|
2012-09-07 15:33:22 +08:00
|
|
|
|
2012-09-27 18:11:03 +08:00
|
|
|
/** \ingroup rpmstrpool
|
|
|
|
* Return length of a string by its pool id. The result is equal to
|
2013-12-02 16:45:33 +08:00
|
|
|
* calling strlen() on a string retrieved through rpmstrPoolStr(), but
|
|
|
|
* the pool might be able to optimize the calculation.
|
2012-09-27 18:11:03 +08:00
|
|
|
* @param pool string pool
|
|
|
|
* @param sid pool id of a string
|
2013-12-02 16:45:33 +08:00
|
|
|
* @return length of the string, 0 for invalid pool or id
|
2012-09-27 18:11:03 +08:00
|
|
|
*/
|
2012-09-07 15:33:22 +08:00
|
|
|
size_t rpmstrPoolStrlen(rpmstrPool pool, rpmsid sid);
|
|
|
|
|
2012-09-27 18:11:03 +08:00
|
|
|
/** \ingroup rpmstrpool
|
|
|
|
* Compare two strings for equality by their ids. The result is equal to
|
|
|
|
* calling rstreq() on two strings retrieved through rpmstrPoolStr() but
|
|
|
|
* when the id's are within the same pool, this runs in constant time.
|
|
|
|
* @param poolA string pool of the first string
|
|
|
|
* @param sidA pool id of the first string
|
|
|
|
* @param poolB string pool of the second string
|
|
|
|
* @param sidB pool id of the second string
|
|
|
|
* @return 1 if strings are equal, 0 otherwise
|
|
|
|
*/
|
2012-09-13 13:48:56 +08:00
|
|
|
int rpmstrPoolStreq(rpmstrPool poolA, rpmsid sidA,
|
|
|
|
rpmstrPool poolB, rpmsid sidB);
|
|
|
|
|
2012-09-27 18:11:03 +08:00
|
|
|
/** \ingroup rpmstrpool
|
|
|
|
* Return the number of strings stored in the pool. This number is
|
|
|
|
* also the highest legal id for the pool.
|
|
|
|
* @param pool string pool
|
|
|
|
* @return number of strings in the pool
|
|
|
|
*/
|
2012-09-26 13:34:40 +08:00
|
|
|
rpmsid rpmstrPoolNumStr(rpmstrPool pool);
|
|
|
|
|
2012-09-07 15:33:22 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _RPMSIDPOOL_H */
|