dbTalk Databases Forums  

B-Tree comparison Function for Unicode Keys/Datum

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss B-Tree comparison Function for Unicode Keys/Datum in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Al
 
Posts: n/a

Default B-Tree comparison Function for Unicode Keys/Datum - 10-10-2005 , 04:35 AM






Hello,

I use the recent C API of Berkely DB to make a kind of an address book
on Windows, the key/data entries are all saved in unicode format. I
need therefore to provide my own B-Tree comparison function as stated
in the documentation.

I made the same things written there:

int compare_int(DB *dbp, const DBT *a, const DBT *b)
{
int ai, bi;

/*
* Returns:
* < 0 if a < b
* = 0 if a = b
* > 0 if a > b
*/
memcpy(&ai, a->data, sizeof(int));
memcpy(&bi, b->data, sizeof(int));
return (ai - bi);
}

... and put this before opening the DB and after creating it:

dbp->set_bt_compare(dbp, compare_int)

Then I get this failure:

E2034 Cannot convert 'int (* (_closure )(__db *,const __db_dbt *,const
__db_dbt *))(__db *,const __db_dbt *,const __db_dbt *)' to 'int
(*)(__db *,const __db_dbt *,const __db_dbt *)'

E2340 Type mismatch in parameter 2 (wanted 'int (*)(__db *,const
__db_dbt *,const __db_dbt *)', got 'void')


I just wanted to see if this is possible, and eventually to change the
function to whatever suits my program. Any clues?

Regards,
Al


Reply With Quote
  #2  
Old   
Perry
 
Posts: n/a

Default Re: B-Tree comparison Function for Unicode Keys/Datum - 10-10-2005 , 07:04 PM






I just tried this (4.3.29 on Windows), and it (this below) compiles for
me:

int mycompare(DB * dbp, const DBT * a1, const DBT * a2)
{
return 1;
}

....
dbp->set_bt_compare(dbp, mycompare);


********

Any chance some macro expansion is plaguing you? (That is just a short
in the dark.)


Reply With Quote
  #3  
Old   
Michael Cahill
 
Posts: n/a

Default Re: B-Tree comparison Function for Unicode Keys/Datum - 10-10-2005 , 11:21 PM



Hi Al,

Is your source a C++ program using the C API? If so, you'll need:

extern "C" {
int compare_int(DB *dbp, const DBT *a, const DBT *b) {
...
}
}

Also, what compiler are you using?

Regards,
Michael.


Reply With Quote
  #4  
Old   
Florian Weimer
 
Posts: n/a

Default Re: B-Tree comparison Function for Unicode Keys/Datum - 10-11-2005 , 05:10 AM



* Al:

Quote:
E2034 Cannot convert 'int (* (_closure )(__db *,const __db_dbt *,const
__db_dbt *))(__db *,const __db_dbt *,const __db_dbt *)' to 'int
(*)(__db *,const __db_dbt *,const __db_dbt *)'
This looks like as if your compare_int function is some member
function. You should make it a global function, and declare it as
'extern "C"'.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.