mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-05-03 07:48:14 +02:00
2002-11-23 Havoc Pennington <hp@pobox.com>
* dbus/dbus-internals.h (_DBUS_INT_MAX): add _DBUS_INT_MIN _DBUS_INT_MAX * dbus/dbus-test.c (main): add list test, and include dbus-test.h as intended * dbus/dbus-hash.c (_dbus_hash_table_remove_string) (_dbus_hash_table_remove_int): return value indicates whether the entry existed to remove * dbus/dbus-list.c: add linked list utility class, with docs and tests * dbus/dbus-hash.c: add TODO item about shrinking the hash bucket array sometimes.
This commit is contained in:
parent
f09921965c
commit
576cdb6e0b
10 changed files with 1168 additions and 15 deletions
18
ChangeLog
18
ChangeLog
|
|
@ -1,3 +1,21 @@
|
|||
2002-11-23 Havoc Pennington <hp@pobox.com>
|
||||
|
||||
* dbus/dbus-internals.h (_DBUS_INT_MAX): add _DBUS_INT_MIN
|
||||
_DBUS_INT_MAX
|
||||
|
||||
* dbus/dbus-test.c (main): add list test, and include
|
||||
dbus-test.h as intended
|
||||
|
||||
* dbus/dbus-hash.c (_dbus_hash_table_remove_string)
|
||||
(_dbus_hash_table_remove_int): return value indicates
|
||||
whether the entry existed to remove
|
||||
|
||||
* dbus/dbus-list.c: add linked list utility class,
|
||||
with docs and tests
|
||||
|
||||
* dbus/dbus-hash.c: add TODO item about shrinking the hash bucket
|
||||
array sometimes.
|
||||
|
||||
2002-11-23 Havoc Pennington <hp@pobox.com>
|
||||
|
||||
* Doxyfile.in (INCLUDE_FILE_PATTERNS): expand DBUS_BEGIN_DECLS/
|
||||
|
|
|
|||
|
|
@ -26,7 +26,9 @@ libdbus_convenience_la_SOURCES= \
|
|||
dbus-hash.c \
|
||||
dbus-hash.h \
|
||||
dbus-internals.c \
|
||||
dbus-internals.h
|
||||
dbus-internals.h \
|
||||
dbus-list.c \
|
||||
dbus-list.h
|
||||
|
||||
libdbus_1_la_LIBADD= $(DBUS_CLIENT_LIBS) libdbus-convenience.la
|
||||
## don't export symbols that start with "_" (we use this
|
||||
|
|
|
|||
|
|
@ -92,6 +92,13 @@
|
|||
*
|
||||
* The guts of DBusHashTable.
|
||||
*
|
||||
* @todo rebuild_table() should be modified to also shrink the hash bucket
|
||||
* array when appropriate; otherwise if a hash table has been
|
||||
* very large but is now small, iteration becomes inefficient.
|
||||
* We should still only shrink when adding hash entries though, not
|
||||
* when removing them, so that you can still iterate over the hash
|
||||
* removing entries. So if you added 5000, removed 4000, the
|
||||
* shrinking would happen next time an entry was added.
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
|
@ -929,8 +936,9 @@ _dbus_hash_table_lookup_int (DBusHashTable *table,
|
|||
*
|
||||
* @param table the hash table.
|
||||
* @param key the hash key.
|
||||
* @returns #TRUE if the entry existed
|
||||
*/
|
||||
void
|
||||
dbus_bool_t
|
||||
_dbus_hash_table_remove_string (DBusHashTable *table,
|
||||
const char *key)
|
||||
{
|
||||
|
|
@ -942,7 +950,12 @@ _dbus_hash_table_remove_string (DBusHashTable *table,
|
|||
entry = (* table->find_function) (table, (char*) key, FALSE, &bucket);
|
||||
|
||||
if (entry)
|
||||
remove_entry (table, bucket, entry);
|
||||
{
|
||||
remove_entry (table, bucket, entry);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -951,8 +964,9 @@ _dbus_hash_table_remove_string (DBusHashTable *table,
|
|||
*
|
||||
* @param table the hash table.
|
||||
* @param key the hash key.
|
||||
* @returns #TRUE if the entry existed
|
||||
*/
|
||||
void
|
||||
dbus_bool_t
|
||||
_dbus_hash_table_remove_int (DBusHashTable *table,
|
||||
int key)
|
||||
{
|
||||
|
|
@ -964,7 +978,12 @@ _dbus_hash_table_remove_int (DBusHashTable *table,
|
|||
entry = (* table->find_function) (table, _DBUS_INT_TO_POINTER (key), FALSE, &bucket);
|
||||
|
||||
if (entry)
|
||||
remove_entry (table, bucket, entry);
|
||||
{
|
||||
remove_entry (table, bucket, entry);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -82,9 +82,9 @@ void* _dbus_hash_table_lookup_string (DBusHashTable *table,
|
|||
const char *key);
|
||||
void* _dbus_hash_table_lookup_int (DBusHashTable *table,
|
||||
int key);
|
||||
void _dbus_hash_table_remove_string (DBusHashTable *table,
|
||||
dbus_bool_t _dbus_hash_table_remove_string (DBusHashTable *table,
|
||||
const char *key);
|
||||
void _dbus_hash_table_remove_int (DBusHashTable *table,
|
||||
dbus_bool_t _dbus_hash_table_remove_int (DBusHashTable *table,
|
||||
int key);
|
||||
dbus_bool_t _dbus_hash_table_insert_string (DBusHashTable *table,
|
||||
char *key,
|
||||
|
|
|
|||
|
|
@ -83,6 +83,17 @@
|
|||
* @param integer the integer to stuff into a pointer.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @def _DBUS_INT_MIN
|
||||
*
|
||||
* Minimum value of type "int"
|
||||
*/
|
||||
/**
|
||||
* @def _DBUS_INT_MAX
|
||||
*
|
||||
* Maximum value of type "int"
|
||||
*/
|
||||
|
||||
/**
|
||||
* Prints a warning message to stderr.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -60,6 +60,9 @@ do {
|
|||
|
||||
char* _dbus_strdup (const char *str);
|
||||
|
||||
#define _DBUS_INT_MIN (-_DBUS_INT_MAX - 1)
|
||||
#define _DBUS_INT_MAX 2147483647
|
||||
|
||||
DBUS_END_DECLS;
|
||||
|
||||
#endif /* DBUS_INTERNALS_H */
|
||||
|
|
|
|||
1029
dbus/dbus-list.c
Normal file
1029
dbus/dbus-list.c
Normal file
File diff suppressed because it is too large
Load diff
73
dbus/dbus-list.h
Normal file
73
dbus/dbus-list.h
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/* -*- mode: C; c-file-style: "gnu" -*- */
|
||||
/* dbus-list.h Generic linked list utility (internal to D-BUS implementation)
|
||||
*
|
||||
* Copyright (C) 2002 Red Hat, Inc.
|
||||
*
|
||||
* Licensed under the Academic Free License version 1.2
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DBUS_LIST_H
|
||||
#define DBUS_LIST_H
|
||||
|
||||
#include <dbus/dbus-memory.h>
|
||||
#include <dbus/dbus-types.h>
|
||||
|
||||
DBUS_BEGIN_DECLS;
|
||||
|
||||
typedef struct DBusList DBusList;
|
||||
|
||||
struct DBusList
|
||||
{
|
||||
DBusList *prev; /**< Previous list node. */
|
||||
DBusList *next; /**< Next list node. */
|
||||
void *data; /**< Data stored at this element. */
|
||||
};
|
||||
|
||||
dbus_bool_t _dbus_list_append (DBusList **list,
|
||||
void *data);
|
||||
dbus_bool_t _dbus_list_prepend (DBusList **list,
|
||||
void *data);
|
||||
dbus_bool_t _dbus_list_insert_before (DBusList **list,
|
||||
DBusList *before_this_link,
|
||||
void *data);
|
||||
dbus_bool_t _dbus_list_insert_after (DBusList **list,
|
||||
DBusList *after_this_link,
|
||||
void *data);
|
||||
dbus_bool_t _dbus_list_remove (DBusList **list,
|
||||
void *data);
|
||||
void _dbus_list_remove_link (DBusList **list,
|
||||
DBusList *link);
|
||||
void _dbus_list_clear (DBusList **list);
|
||||
DBusList* _dbus_list_get_first_link (DBusList **list);
|
||||
DBusList* _dbus_list_get_last_link (DBusList **list);
|
||||
void* _dbus_list_get_last (DBusList **list);
|
||||
void* _dbus_list_get_first (DBusList **list);
|
||||
void* _dbus_list_pop_first (DBusList **list);
|
||||
void* _dbus_list_pop_last (DBusList **list);
|
||||
dbus_bool_t _dbus_list_copy (DBusList **list,
|
||||
DBusList **dest);
|
||||
int _dbus_list_get_length (DBusList **list);
|
||||
|
||||
|
||||
|
||||
#define _dbus_list_get_next_link(list, link) ((link)->next == *(list) ? NULL : (link)->next)
|
||||
#define _dbus_list_get_prev_link(list, link) ((link)->prev == *(list) ? NULL : (link)->prev)
|
||||
|
||||
DBUS_END_DECLS;
|
||||
|
||||
#endif /* DBUS_LIST_H */
|
||||
|
|
@ -22,23 +22,20 @@
|
|||
*/
|
||||
|
||||
#include "dbus-types.h"
|
||||
#include "dbus-test.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/* To add a test, write a function like this one,
|
||||
* declare it here, define it in the file to be tested,
|
||||
* then call it from main() below. Test functions
|
||||
* should return FALSE on failure.
|
||||
*/
|
||||
dbus_bool_t _dbus_hash_test (void);
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char **argv)
|
||||
{
|
||||
printf ("%s: running linked list tests\n", argv[0]);
|
||||
if (!_dbus_list_test ())
|
||||
return 1;
|
||||
|
||||
printf ("%s: running hash table tests\n", argv[0]);
|
||||
if (!_dbus_hash_test ())
|
||||
return 1;
|
||||
|
||||
|
||||
printf ("%s: completed successfully\n", argv[0]);
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -27,5 +27,6 @@
|
|||
#include <dbus/dbus-types.h>
|
||||
|
||||
dbus_bool_t _dbus_hash_test (void);
|
||||
dbus_bool_t _dbus_list_test (void);
|
||||
|
||||
#endif /* DBUS_TEST_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue