Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5788671

Browse files
committed
revise AGMDB_getKeyNum() and add AGMDB_getAllKeysValues()
1 parent80a6a38 commit5788671

File tree

2 files changed

+61
-6
lines changed

2 files changed

+61
-6
lines changed

‎apache2/ag_mdb/ag_mdb.cpp‎

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,10 +1079,11 @@ int AGMDB_removeStale(struct agmdb_handler *dbm) {
10791079
** Get the number of keys in a database.
10801080
** You have to get SHARED or EXCLUSIVE LOCK of the database before calling this function.
10811081
** @param dbm: the database you want to read.
1082-
** return: number of keys in the database
1082+
** @param keynum: the value to store the number of keys in the database
1083+
** return: AGMDB_SUCCESS if no error
10831084
** or AGMDB_FAIL if failed.
10841085
*/
1085-
unsignedintAGMDB_getKeyNum(structagmdb_handler *dbm) {
1086+
intAGMDB_getKeyNum(structagmdb_handler *dbm,int* keynum) {
10861087
CPTR_VOID shm_base;
10871088
unsignedint timelist_cnt =0;
10881089
PTR_VOID entry_addr;
@@ -1098,10 +1099,10 @@ unsigned int AGMDB_getKeyNum(struct agmdb_handler *dbm) {
10981099
timelist_cnt ++;
10991100
entry_id = *ENTRY_TIME_NEXT(entry_addr);
11001101
}
1101-
1102+
*keynum = timelist_cnt;
11021103
// Check the length of expirartion time linklist and the busy entry counter;
11031104
if(timelist_cnt == *SHM_BUSY_ENTRY_CNT(shm_base))
1104-
returntimelist_cnt;
1105+
returnAGMDB_SUCCESS;
11051106
else
11061107
return AGMDB_FAIL;
11071108
}
@@ -1122,6 +1123,45 @@ int AGMDB_getHashValue(const char* key, int key_len, int output_val_range) {
11221123
returnAGMDB_hash(key, key_len, output_val_range);
11231124
}
11241125

1126+
/**
1127+
** Get the const pointers of all keys and values in a database.
1128+
** You have to get SHARED or EXCLUSIVE LOCK of the database before calling this function.
1129+
** You should call AGMDB_getKeyNum() before to get the number of keys, then assign proper space for keys and values. Although, you can just assign a large enough space for these two arrays.
1130+
** @param dbm: the database you want to read.
1131+
** @param array_size: the maximum size of key array and value array
1132+
** @param keys: the array to store pointers of keys.
1133+
** @param values: the array to store pointers of values.
1134+
** @param vals_len: the array to store length of values.
1135+
** return: AGMDB_SUCCESS if no error
1136+
** or AGMDB_FAIL if failed.
1137+
*/
1138+
intAGMDB_getAllKeysValues(structagmdb_handler *dbm,int array_size,constchar* keys[],constchar * values[],unsignedint vals_len[]) {
1139+
CPTR_VOID shm_base;
1140+
PTR_VOID entry_addr;
1141+
PTR_OFFSET entry_id;
1142+
PTR_OFFSET* time_list_head;
1143+
int keys_counter =0;
1144+
1145+
if(dbm ==NULL)
1146+
return AGMDB_FAIL;
1147+
shm_base = (CPTR_VOID)(dbm->shm_base);
1148+
time_list_head =SHM_EXPIRE_TIME_LIST_HEAD(shm_base);
1149+
1150+
entry_id = *time_list_head;
1151+
while(entry_id != AGMDB_INVALID_INDEX){
1152+
if (keys_counter >= array_size)
1153+
return AGMDB_FAIL;
1154+
entry_addr =ENTRY_ADDR(shm_base, entry_id);
1155+
keys[keys_counter] =ENTRY_KEY(entry_addr);
1156+
values[keys_counter] =ENTRY_DATA(entry_addr);
1157+
vals_len[keys_counter] = *ENTRY_LENG(entry_addr);
1158+
entry_id = *ENTRY_TIME_NEXT(entry_addr);
1159+
keys_counter++;
1160+
}
1161+
1162+
return AGMDB_SUCCESS;
1163+
}
1164+
11251165

11261166

11271167

‎apache2/ag_mdb/ag_mdb_external.h‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,11 @@ int AGMDB_removeStale(struct agmdb_handler *dbm);
169169
** Get the number of keys in a database.
170170
** You have to get SHARED or EXCLUSIVE LOCK of the database before calling this function.
171171
** @param dbm: the database you want to read.
172-
** return: number of keys in the database
172+
** @param keynum: the value to store the number of keys in the database
173+
** return: AGMDB_SUCCESS if no error
173174
** or AGMDB_FAIL if failed.
174175
*/
175-
unsignedintAGMDB_getKeyNum(structagmdb_handler*dbm);
176+
intAGMDB_getKeyNum(structagmdb_handler*dbm,int*keynum);
176177

177178
/**
178179
** Use AGMDB's hash function to hash a string into an integer.
@@ -184,6 +185,20 @@ unsigned int AGMDB_getKeyNum(struct agmdb_handler *dbm);
184185
*/
185186
intAGMDB_getHashValue(constchar*key,intkey_len,inthash_nums);
186187

188+
/**
189+
** Get the const pointers of all keys and values in a database.
190+
** You have to get SHARED or EXCLUSIVE LOCK of the database before calling this function.
191+
** You should call AGMDB_getKeyNum() before to get the number of keys, then assign proper space for keys and values. Although, you can just assign a large enough space for these two arrays.
192+
** @param dbm: the database you want to read.
193+
** @param array_size: the maximum size of key array and value array
194+
** @param keys: the array to store pointers of keys.
195+
** @param values: the array to store pointers of values.
196+
** @param vals_len: the array to store length of values.
197+
** return: AGMDB_SUCCESS if no error
198+
** or AGMDB_FAIL if failed.
199+
*/
200+
intAGMDB_getAllKeysValues(structagmdb_handler*dbm,intarray_size,constchar*keys[],constchar*values[],unsignedintvals_len[]);
201+
187202
#ifdef__cplusplus
188203
}
189204
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp