Added silc_hash_table_find_by_context_ext.
authorPekka Riikonen <priikone@silcnet.org>
Thu, 6 Nov 2003 19:11:30 +0000 (19:11 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 6 Nov 2003 19:11:30 +0000 (19:11 +0000)
configure.in.pre
lib/silcutil/silchashtable.c
lib/silcutil/silchashtable.h

index 4bb362c80a9c18ec25db05ff880927b44369a7a1..04baa04e3525378f6cd6db78235c1fe38831dc37 100644 (file)
@@ -3,7 +3,7 @@
 #
 #  Author: Pekka Riikonen <priikone@silcnet.org>
 #
-#  Copyright (C) 2000 - 2002 Pekka Riikonen
+#  Copyright (C) 2000 - 2003 Pekka Riikonen
 #
 #  This program is free software; you can redistribute it and/or modify
 #  it under the terms of the GNU General Public License as published by
@@ -70,7 +70,7 @@ AC_DEFINE(SILC_DIST_DEFINE)
 # where [LIB] is LIBSILC and LIBSILCCLIENT, and where "functions" means
 # functions public interfaces.
 #
-# The LIB_BASE_VERSION defines the SILC software major.minor version and 
+# The LIB_BASE_VERSION defines the SILC software major.minor version and
 # it is increment only when these version numbers actually change.
 #
 
@@ -79,9 +79,9 @@ AC_DEFINE(SILC_DIST_DEFINE)
 LIB_BASE_VERSION=1.0
 
 # libsilc versions
-LIBSILC_CURRENT=2
+LIBSILC_CURRENT=3
 LIBSILC_REVISION=0
-LIBSILC_AGE=0
+LIBSILC_AGE=1
 
 # libsilcclient versions
 LIBSILCCLIENT_CURRENT=2
@@ -541,14 +541,14 @@ AC_ARG_WITH(socks4,
       *)
         AC_MSG_RESULT(yes)
         socks=4
-    
+
         if test -d "$withval/include"; then
           CFLAGS="$CFLAGS -I$withval/include"
         fi
         if test -d "$withval/lib"; then
           LDFLAGS="$LDFLAGS -L$withval/lib"
         fi
-    
+
         LIBS="-lsocks $LIBS"
         ;;
     esac
@@ -658,14 +658,14 @@ AC_ARG_WITH(gmp,
         ;;
       *)
         AC_MSG_RESULT(yes)
-    
+
         if test -d "$withval/include"; then
           CFLAGS="$CFLAGS -I$withval/include"
         fi
         if test -d "$withval/lib"; then
           LDFLAGS="$LDFLAGS -L$withval/lib"
         fi
-    
+
         LIBS="-lgmp $LIBS"
         ;;
     esac
@@ -779,11 +779,11 @@ if test x$check_iconv = xtrue; then
   SAVE_CFLAGS="$CFLAGS"
   SAVE_LDFLAGS="$LDFLAGS"
   SAVE_CPPFLAGS="$CPPFLAGS"
-    
+
   for dir in `echo "/usr/local /usr/pkg /usr/contrib"`; do
     if test x$has_iconv = xfalse; then
       AC_MSG_RESULT(searching in $dir...)
-     
+
       if test -d $dir/include; then
         CPPFLAGS="$CPPFLAGS -I$dir/include"
         CFLAGS="$CFLAGS -I$dir/include"
@@ -791,10 +791,10 @@ if test x$check_iconv = xtrue; then
       if test -d $dir/lib; then
         LDFLAGS="$LDFLAGS -L$dir/lib"
       fi
-    
+
       # XXX
       unset ac_cv_header__iconv_h_ ac_cv_header_iconv_h || true
-      
+
       AC_CHECK_HEADERS(iconv.h,
         [
           LIBS="$LIBS -liconv"
@@ -811,14 +811,14 @@ if test x$check_iconv = xtrue; then
             ],
             [
               echo "yes"
-              has_iconv=true 
+              has_iconv=true
               AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
             ],
             [
               echo "no"
               has_iconv=false
-              LIBS="$SAVE_LIBS"    
+
+              LIBS="$SAVE_LIBS"
               CFLAGS="$SAVE_CFLAGS"
               LDFLAGS="$SAVE_LDFLAGS"
               CPPFLAGS="$SAVE_CPPFLAGS"
@@ -878,7 +878,7 @@ has_threads=false
 AC_MSG_CHECKING(whether to search for POSIX threads)
 AC_ARG_WITH(pthreads,
   [[  --with-pthreads[=DIR]   use POSIX threads [search in DIR/include and DIR/lib]]],
-  [ 
+  [
     case "${withval}" in
       no)
         check_threads=false
@@ -902,7 +902,7 @@ if test x$check_threads = xtrue; then
   SAVE_CFLAGS="$CFLAGS"
   SAVE_LDFLAGS="$LDFLAGS"
   SAVE_CPPFLAGS="$CPPFLAGS"
-  
+
   AC_MSG_RESULT(yes)
   AC_CHECK_HEADERS(pthread.h,
     [
@@ -926,7 +926,7 @@ if test x$check_threads = xtrue; then
       for dir in `echo "/usr/local /usr/pkg /usr/contrib /usr/pkg/pthreads /usr/local/pthreads"`; do
         if test x$has_threads = xfalse; then
           AC_MSG_RESULT(searching in $dir...)
-  
+
           if test -d $dir/include; then
             CPPFLAGS="$CPPFLAGS -I$dir/include"
             CFLAGS="$CFLAGS -I$dir/include"
@@ -939,7 +939,7 @@ if test x$check_threads = xtrue; then
           unset ac_cv_header__pthread_h_ ac_cv_header_pthread_h || true
 
           AC_CHECK_HEADERS(pthread.h,
-            [ 
+            [
               LIBS="$LIBS -lpthread"
               AC_CHECK_LIB(pthread, pthread_attr_init, has_threads=true,
                 [
index 6478382a94e51e19eadfe4d6ae261aafa1cceca9..56b6ff44e4a1aa5ceef9877cb897078b374e4a6b 100644 (file)
@@ -653,21 +653,8 @@ bool silc_hash_table_del_by_context_ext(SilcHashTable ht, void *key,
 bool silc_hash_table_find(SilcHashTable ht, void *key,
                          void **ret_key, void **ret_context)
 {
-  SilcHashTableEntry *entry;
-
-  entry = silc_hash_table_find_internal_simple(ht, key, ht->hash,
-                                              ht->hash_user_context,
-                                              ht->compare,
-                                              ht->compare_user_context);
-  if (*entry == NULL)
-    return FALSE;
-
-  if (ret_key)
-    *ret_key = (*entry)->key;
-  if (ret_context)
-    *ret_context = (*entry)->context;
-
-  return TRUE;
+  return silc_hash_table_find_ext(ht, key, ret_key, ret_context,
+                                 NULL, NULL, NULL, NULL);
 }
 
 /* Same as above but with specified hash and comparison functions. */
@@ -706,13 +693,31 @@ bool silc_hash_table_find_ext(SilcHashTable ht, void *key,
 
 bool silc_hash_table_find_by_context(SilcHashTable ht, void *key,
                                     void *context, void **ret_key)
+{
+  return silc_hash_table_find_by_context_ext(ht, key, context, ret_key,
+                                            NULL, NULL, NULL, NULL);
+}
+
+/* Same as above but with specified hash and comparison functions. */
+
+bool silc_hash_table_find_by_context_ext(SilcHashTable ht, void *key,
+                                        void *context, void **ret_key,
+                                        SilcHashFunction hash,
+                                        void *hash_user_context,
+                                        SilcHashCompare compare,
+                                        void *compare_user_context)
 {
   SilcHashTableEntry *entry;
 
   entry = silc_hash_table_find_internal_context(ht, key, context, NULL,
-                                               ht->hash,
+                                               hash ? hash : ht->hash,
+                                               hash_user_context ?
+                                               hash_user_context :
                                                ht->hash_user_context,
+                                               compare ? compare :
                                                ht->compare,
+                                               compare_user_context ?
+                                               compare_user_context :
                                                ht->compare_user_context);
   if (!entry || !(*entry))
     return FALSE;
index 478ea184a6a23128f8d710c899bb26a4de2a151b..612038034c9f4c38414c0e8e2f9e75cd4f87d860 100644 (file)
@@ -1,10 +1,10 @@
 /*
 
-  silchashtable.h 
+  silchashtable.h
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2001 - 2002 Pekka Riikonen
+  Copyright (C) 2001 - 2003 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -47,7 +47,7 @@
 /****s* silcutil/SilcHashTableAPI/SilcHashTable
  *
  * NAME
- * 
+ *
  *    typedef struct SilcHashTableStruct *SilcHashTable;
  *
  * DESCRIPTION
@@ -63,13 +63,13 @@ typedef struct SilcHashTableStruct *SilcHashTable;
 /****s* silcutil/SilcHashTableAPI/SilcHashTableList
  *
  * NAME
- * 
+ *
  *    typedef struct SilcHashTableListStruct SilcHashTableList;
  *
  * DESCRIPTION
  *
  *    This structure is used to tarverse the hash table. This structure
- *    is given as argument to the silc_hash_table_list function to 
+ *    is given as argument to the silc_hash_table_list function to
  *    initialize it and then used to traverse the hash table with the
  *    silc_hash_table_get function. It needs not be allocated or freed.
  *
@@ -114,7 +114,7 @@ typedef SilcUInt32 (*SilcHashFunction)(void *key, void *user_context);
  *
  * SYNOPSIS
  *
- *    typedef bool (*SilcHashCompare)(void *key1, void *key2, 
+ *    typedef bool (*SilcHashCompare)(void *key1, void *key2,
  *                                    void *user_context);
  *
  * DESCRIPTION
@@ -132,25 +132,25 @@ typedef bool (*SilcHashCompare)(void *key1, void *key2, void *user_context);
  *
  * SYNOPSIS
  *
- *    typedef void (*SilcHashDestructor)(void *key, void *context, 
+ *    typedef void (*SilcHashDestructor)(void *key, void *context,
  *                                       void *user_context);
  *
  * DESCRIPTION
  *
- *    A destructor callback that the library will call to destroy the 
+ *    A destructor callback that the library will call to destroy the
  *    `key' and `context'.  The application provides the function when
  *    allocating a new hash table. The `user_context' is application
  *    specific context and is delivered to the callback.
  *
  ***/
-typedef void (*SilcHashDestructor)(void *key, void *context, 
+typedef void (*SilcHashDestructor)(void *key, void *context,
                                   void *user_context);
 
 /****f* silcutil/SilcHashTableAPI/SilcHashForeach
  *
  * SYNOPSIS
  *
- *    typedef void (*SilcHashForeach)(void *key, void *context, 
+ *    typedef void (*SilcHashForeach)(void *key, void *context,
  *                                    void *user_context);
  *
  * DESCRIPTION
@@ -168,7 +168,7 @@ typedef void (*SilcHashForeach)(void *key, void *context, void *user_context);
  *
  * SYNOPSIS
  *
- *    SilcHashTable silc_hash_table_alloc(SilcUInt32 table_size, 
+ *    SilcHashTable silc_hash_table_alloc(SilcUInt32 table_size,
  *                                        SilcHashFunction hash,
  *                                        void *hash_user_context,
  *                                        SilcHashCompare compare,
@@ -188,7 +188,7 @@ typedef void (*SilcHashForeach)(void *key, void *context, void *user_context);
  *    are optional.
  *
  ***/
-SilcHashTable silc_hash_table_alloc(SilcUInt32 table_size, 
+SilcHashTable silc_hash_table_alloc(SilcUInt32 table_size,
                                    SilcHashFunction hash,
                                    void *hash_user_context,
                                    SilcHashCompare compare,
@@ -291,7 +291,7 @@ bool silc_hash_table_del(SilcHashTable ht, void *key);
  *
  * SYNOPSIS
  *
- *    bool silc_hash_table_del_by_context(SilcHashTable ht, void *key, 
+ *    bool silc_hash_table_del_by_context(SilcHashTable ht, void *key,
  *                                        void *context);
  *
  * DESCRIPTION
@@ -302,7 +302,7 @@ bool silc_hash_table_del(SilcHashTable ht, void *key);
  *    be used to check whether the correct entry is being deleted.
  *
  ***/
-bool silc_hash_table_del_by_context(SilcHashTable ht, void *key, 
+bool silc_hash_table_del_by_context(SilcHashTable ht, void *key,
                                    void *context);
 
 /****f* silcutil/SilcHashTableAPI/silc_hash_table_find
@@ -315,7 +315,7 @@ bool silc_hash_table_del_by_context(SilcHashTable ht, void *key,
  * DESCRIPTION
  *
  *    Finds the entry in the hash table by the provided `key' as fast as
- *    possible. Return TRUE if the entry was found and FALSE otherwise. 
+ *    possible. Return TRUE if the entry was found and FALSE otherwise.
  *    The found entry is returned to the `ret_key' and `ret_context',
  *    respectively. If the `ret_key and `ret_context' are NULL then this
  *    maybe used only to check whether given key exists in the table.
@@ -350,7 +350,7 @@ bool silc_hash_table_find_by_context(SilcHashTable ht, void *key,
  * SYNOPSIS
  *
  *    void silc_hash_table_find_foreach(SilcHashTable ht, void *key,
- *                                      SilcHashForeach foreach, 
+ *                                      SilcHashForeach foreach,
  *                                      void *user_context);
  *
  * DESCRIPTION
@@ -450,7 +450,7 @@ void silc_hash_table_list_reset(SilcHashTableList *htl);
  *
  * SYNOPSIS
  *
- *    bool silc_hash_table_get(SilcHashTableList *htl, void **key, 
+ *    bool silc_hash_table_get(SilcHashTableList *htl, void **key,
  *                             void **context);
  *
  * DESCRIPTION
@@ -471,7 +471,7 @@ bool silc_hash_table_get(SilcHashTableList *htl, void **key, void **context);
  * SYNOPSIS
  *
  *    void silc_hash_table_add_ext(SilcHashTable ht, void *key, void *context,
- *                                 SilcHashFunction hash, 
+ *                                 SilcHashFunction hash,
  *                                 void *hash_user_context);
  *
  * DESCRIPTION
@@ -492,9 +492,9 @@ void silc_hash_table_add_ext(SilcHashTable ht, void *key, void *context,
  *
  * SYNOPSIS
  *
- *    void silc_hash_table_replace_ext(SilcHashTable ht, void *key, 
+ *    void silc_hash_table_replace_ext(SilcHashTable ht, void *key,
  *                                     void *context,
- *                                     SilcHashFunction hash, 
+ *                                     SilcHashFunction hash,
  *                                     void *hash_user_context);
  *
  * DESCRIPTION
@@ -509,7 +509,7 @@ void silc_hash_table_add_ext(SilcHashTable ht, void *key, void *context,
  *
  ***/
 void silc_hash_table_replace_ext(SilcHashTable ht, void *key, void *context,
-                                SilcHashFunction hash, 
+                                SilcHashFunction hash,
                                 void *hash_user_context);
 
 /****f* silcutil/SilcHashTableAPI/silc_hash_table_del_ext
@@ -517,9 +517,9 @@ void silc_hash_table_replace_ext(SilcHashTable ht, void *key, void *context,
  * SYNOPSIS
  *
  *    bool silc_hash_table_del_ext(SilcHashTable ht, void *key,
- *                                 SilcHashFunction hash, 
+ *                                 SilcHashFunction hash,
  *                                 void *hash_user_context,
- *                                 SilcHashCompare compare, 
+ *                                 SilcHashCompare compare,
  *                                 void *compare_user_context,
  *                                 SilcHashDestructor destructor,
  *                                 void *destructor_user_context);
@@ -539,9 +539,9 @@ void silc_hash_table_replace_ext(SilcHashTable ht, void *key, void *context,
  *
  ***/
 bool silc_hash_table_del_ext(SilcHashTable ht, void *key,
-                            SilcHashFunction hash, 
+                            SilcHashFunction hash,
                             void *hash_user_context,
-                            SilcHashCompare compare, 
+                            SilcHashCompare compare,
                             void *compare_user_context,
                             SilcHashDestructor destructor,
                             void *destructor_user_context);
@@ -550,11 +550,11 @@ bool silc_hash_table_del_ext(SilcHashTable ht, void *key,
  *
  * SYNOPSIS
  *
- *    bool silc_hash_table_del_by_context_ext(SilcHashTable ht, void *key, 
+ *    bool silc_hash_table_del_by_context_ext(SilcHashTable ht, void *key,
  *                                            void *context,
- *                                            SilcHashFunction hash, 
+ *                                            SilcHashFunction hash,
  *                                            void *hash_user_context,
- *                                            SilcHashCompare compare, 
+ *                                            SilcHashCompare compare,
  *                                            void *compare_user_context,
  *                                            SilcHashDestructor destructor,
  *                                            void *destructor_user_context);
@@ -574,11 +574,11 @@ bool silc_hash_table_del_ext(SilcHashTable ht, void *key,
  *    specific destructor function.
  *
  ***/
-bool silc_hash_table_del_by_context_ext(SilcHashTable ht, void *key, 
+bool silc_hash_table_del_by_context_ext(SilcHashTable ht, void *key,
                                        void *context,
-                                       SilcHashFunction hash, 
+                                       SilcHashFunction hash,
                                        void *hash_user_context,
-                                       SilcHashCompare compare, 
+                                       SilcHashCompare compare,
                                        void *compare_user_context,
                                        SilcHashDestructor destructor,
                                        void *destructor_user_context);
@@ -589,15 +589,15 @@ bool silc_hash_table_del_by_context_ext(SilcHashTable ht, void *key,
  *
  *    bool silc_hash_table_find_ext(SilcHashTable ht, void *key,
  *                                  void **ret_key, void **ret_context,
- *                                  SilcHashFunction hash, 
+ *                                  SilcHashFunction hash,
  *                                  void *hash_user_context,
- *                                  SilcHashCompare compare, 
+ *                                  SilcHashCompare compare,
  *                                  void *compare_user_context);
  *
  * DESCRIPTION
  *
  *    Finds the entry in the hash table by the provided `key' as fast as
- *    possible. Return TRUE if the entry was found and FALSE otherwise. 
+ *    possible. Return TRUE if the entry was found and FALSE otherwise.
  *    The found entry is returned to the `ret_key' and `ret_context',
  *    respectively. If the `ret_key and `ret_context' are NULL then this
  *    maybe used only to check whether given key exists in the table.
@@ -610,21 +610,55 @@ bool silc_hash_table_del_by_context_ext(SilcHashTable ht, void *key,
  ***/
 bool silc_hash_table_find_ext(SilcHashTable ht, void *key,
                              void **ret_key, void **ret_context,
-                             SilcHashFunction hash, 
+                             SilcHashFunction hash,
                              void *hash_user_context,
-                             SilcHashCompare compare, 
+                             SilcHashCompare compare,
                              void *compare_user_context);
 
+/****f* silcutil/SilcHashTableAPI/silc_hash_table_find_by_context_ext
+ *
+ * SYNOPSIS
+ *
+ *    bool silc_hash_table_find_by_context_ext(SilcHashTable ht, void *key,
+ *                                             void *context, void **ret_key,
+ *                                             SilcHashFunction hash,
+ *                                             void *hash_user_context,
+ *                                             SilcHashCompare compare,
+ *                                             void *compare_user_context);
+ *
+ * DESCRIPTION
+ *
+ *    Finds the entry in the hash table by the provided `key' and
+ *    `context' as fast as possible.  This is handy function when there
+ *    can be multiple same keys in the hash table.  By using this function
+ *    the specific key with specific context can be found.  Return
+ *    TRUE if the entry with the key and context was found and FALSE
+ *    otherwise.  The function returns only the key to `ret_key' since
+ *    the caller already knows the context.
+ *
+ *    The `hash' and `hash_user_context' are application specified hash
+ *    function. If not provided the hash table's default is used.
+ *    The `compare' and `compare_user_context' are application specified
+ *    comparing function. If not provided the hash table's default is used.
+ *
+ ***/
+bool silc_hash_table_find_by_context_ext(SilcHashTable ht, void *key,
+                                        void *context, void **ret_key,
+                                        SilcHashFunction hash,
+                                        void *hash_user_context,
+                                        SilcHashCompare compare,
+                                        void *compare_user_context);
+
 /****f* silcutil/SilcHashTableAPI/silc_hash_table_find_foreach_ext
  *
  * SYNOPSIS
  *
  *    void silc_hash_table_find_foreach_ext(SilcHashTable ht, void *key,
- *                                          SilcHashFunction hash, 
+ *                                          SilcHashFunction hash,
  *                                          void *hash_user_context,
- *                                          SilcHashCompare compare, 
+ *                                          SilcHashCompare compare,
  *                                          void *compare_user_context,
- *                                          SilcHashForeach foreach, 
+ *                                          SilcHashForeach foreach,
  *                                          void *foreach_user_context);
  *
  * DESCRIPTION
@@ -649,11 +683,11 @@ bool silc_hash_table_find_ext(SilcHashTable ht, void *key,
  *
  ***/
 void silc_hash_table_find_foreach_ext(SilcHashTable ht, void *key,
-                                     SilcHashFunction hash, 
+                                     SilcHashFunction hash,
                                      void *hash_user_context,
-                                     SilcHashCompare compare, 
+                                     SilcHashCompare compare,
                                      void *compare_user_context,
-                                     SilcHashForeach foreach, 
+                                     SilcHashForeach foreach,
                                      void *foreach_user_context);
 
 /****f* silcutil/SilcHashTableAPI/silc_hash_table_rehash_ext
@@ -661,7 +695,7 @@ void silc_hash_table_find_foreach_ext(SilcHashTable ht, void *key,
  * SYNOPSIS
  *
  *    void silc_hash_table_rehash_ext(SilcHashTable ht, SilcUInt32 new_size,
- *                                    SilcHashFunction hash, 
+ *                                    SilcHashFunction hash,
  *                                    void *hash_user_context);
  *
  * DESCRIPTION
@@ -676,7 +710,7 @@ void silc_hash_table_find_foreach_ext(SilcHashTable ht, void *key,
  *
  ***/
 void silc_hash_table_rehash_ext(SilcHashTable ht, SilcUInt32 new_size,
-                               SilcHashFunction hash, 
+                               SilcHashFunction hash,
                                void *hash_user_context);
 
 #endif