/* */
/* */
/* */
-/* (C) 2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
+/* (C) 2003-2008 Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* A string pool is used to store identifiers and other strings. Each string
- * stored in the pool has a unique id, which may be used to access the string
- * in the pool. Identical strings are only stored once in the pool and have
- * identical ids. This means that instead of comparing strings, just the
- * string pool ids must be compared.
- */
+** stored in the pool has a unique ID, which may be used to access the string
+** in the pool. Identical strings are only stored once in the pool and have
+** identical IDs. This means that instead of comparing strings, just the
+** string pool IDs must be compared.
+*/
/* common */
-#include "coll.h"
-#include "inline.h"
+#include "hashtab.h"
#include "strbuf.h"
-/* Opaque entry */
-typedef struct StrPoolEntry StrPoolEntry;
+/* Opaque string pool entry */
+typedef struct StringPoolEntry StringPoolEntry;
-typedef struct StrPool StrPool;
-struct StrPool {
- StrPoolEntry* Tab[211]; /* Entry hash table */
- Collection Entries; /* Entries sorted by number */
- unsigned TotalSize; /* Total size of all string data */
-};
+/* A string pool */
+typedef struct StringPool StringPool;
-StrPool* InitStrPool (StrPool* P);
-/* Initialize a string pool */
-
-void DoneStrPool (StrPool* P);
-/* Free the data of a string pool (but not the data itself) */
-
-StrPool* NewStrPool (void);
+StringPool* NewStringPool (unsigned HashSlots);
/* Allocate, initialize and return a new string pool */
-void FreeStrPool (StrPool* P);
+void FreeStringPool (StringPool* P);
/* Free a string pool */
-void SP_Use (char* Buffer, unsigned Size);
-/* Delete existing data and use the data from Buffer instead. Buffer must be
- * allocated on the heap and will be freed using xfree() if necessary.
- */
-
-const char* SP_Get (const StrPool* P, unsigned Index);
+const StrBuf* SP_Get (const StringPool* P, unsigned Index);
/* Return a string from the pool. Index must exist, otherwise FAIL is called. */
-unsigned SP_Add (StrPool* P, const char* S);
+unsigned SP_Add (StringPool* P, const StrBuf* S);
+/* Add a string buffer to the buffer and return the index. If the string does
+** already exist in the pool, SP_AddBuf will just return the index of the
+** existing string.
+*/
+
+unsigned SP_AddStr (StringPool* P, const char* S);
/* Add a string to the buffer and return the index. If the string does already
- * exist in the pool, SP_Add will just return the index of the existing string.
- */
+** exist in the pool, SP_Add will just return the index of the existing string.
+*/
-#if defined(HAVE_INLINE)
-INLINE unsigned SB_GetCount (const StrPool* P)
+unsigned SP_GetCount (const StringPool* P);
/* Return the number of strings in the pool */
-{
- return CollCount (&P->Entries);
-}
-#else
-# define SB_GetCount(P) CollCount (&(P)->Entries)
-#endif
/* End of strpool.h */
#endif
-
-
-