]> git.sur5r.net Git - cc65/blobdiff - src/common/strpool.c
Merge branch 'master' into master
[cc65] / src / common / strpool.c
index 12dab95b0e060543bfd6a6d52bdb85dbc334045e..244681afdbe93277ee996d67c5ed51a5b9f2e225 100644 (file)
 
 
 /* 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 stored only 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 stored only once in the pool and have
+** identical ids. This means that instead of comparing strings, just the
+** string pool ids must be compared.
+*/
 
 
 
@@ -68,9 +68,9 @@ static const void* HT_GetKey (const void* Entry);
 
 static int HT_Compare (const void* Key1, const void* Key2);
 /* Compare two keys. The function must return a value less than zero if
- * Key1 is smaller than Key2, zero if both are equal, and a value greater
- * than zero if Key1 is greater then Key2.
- */
+** Key1 is smaller than Key2, zero if both are equal, and a value greater
+** than zero if Key1 is greater then Key2.
+*/
 
 
 
@@ -154,9 +154,9 @@ static const void* HT_GetKey (const void* Entry)
 
 static int HT_Compare (const void* Key1, const void* Key2)
 /* Compare two keys. The function must return a value less than zero if
- * Key1 is smaller than Key2, zero if both are equal, and a value greater
- * than zero if Key1 is greater then Key2.
- */
+** Key1 is smaller than Key2, zero if both are equal, and a value greater
+** than zero if Key1 is greater then Key2.
+*/
 {
     return SB_Compare (Key1, Key2);
 }
@@ -228,15 +228,15 @@ const StrBuf* SP_Get (const StringPool* P, unsigned Index)
 
 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.
- */
+** already exist in the pool, SP_AddBuf will just return the index of the
+** existing string.
+*/
 {
     /* Search for a matching entry in the hash table */
-    StringPoolEntry* E = HT_FindEntry (&P->Tab, S);
+    StringPoolEntry* E = HT_Find (&P->Tab, S);
 
     /* Did we find it? */
-    if (E != 0) {
+    if (E == 0) {
 
         /* We didn't find the entry, so create a new one */
         E = NewStringPoolEntry (S, CollCount (&P->Entries));
@@ -245,7 +245,7 @@ unsigned SP_Add (StringPool* P, const StrBuf* S)
         CollAppend (&P->Entries, E);
 
         /* Insert the new entry into the hash table */
-        HT_InsertEntry (&P->Tab, E);
+        HT_Insert (&P->Tab, E);
 
         /* Add up the string size */
         P->TotalSize += SB_GetLen (&E->Buf);
@@ -259,14 +259,14 @@ unsigned SP_Add (StringPool* P, const StrBuf* S)
 
 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.
+*/
 {
     unsigned Id;
 
     /* First make a string buffer, then add it. This is some overhead, but the
-     * routine will probably go.
-     */
+    ** routine will probably go.
+    */
     StrBuf Buf;
     Id = SP_Add (P, SB_InitFromString (&Buf, S));
 
@@ -276,3 +276,8 @@ unsigned SP_AddStr (StringPool* P, const char* S)
 
 
 
+unsigned SP_GetCount (const StringPool* P)
+/* Return the number of strings in the pool */
+{
+    return CollCount (&P->Entries);
+}