https://www.liblfds.org/mediawiki/index.php?title=r7.1.0:Macro_LFDS710_BTREE_AU_SET_KEY_IN_ELEMENT&feed=atom&action=historyr7.1.0:Macro LFDS710 BTREE AU SET KEY IN ELEMENT - Revision history2024-03-29T07:04:00ZRevision history for this page on the wikiMediaWiki 1.36.0https://www.liblfds.org/mediawiki/index.php?title=r7.1.0:Macro_LFDS710_BTREE_AU_SET_KEY_IN_ELEMENT&diff=735&oldid=prevAdmin: 1 revision imported2016-05-07T21:04:59Z<p>1 revision imported</p>
<p><b>New page</b></p><div>{{DISPLAYTITLE:macro LFDS710_BTREE_AU_SET_KEY_IN_ELEMENT}}<br />
==Source File==<br />
└───liblfds710<br />
└───inc<br />
└───liblfds710<br />
lfds710_btree_addonly_unbalanced.h<br />
<br />
==Opaque Structures==<br />
struct [[r7.1.0:struct lfds710_btree_au_element|lfds710_btree_au_element]];<br />
<br />
==Macro==<br />
#define LFDS710_BTREE_AU_SET_KEY_IN_ELEMENT( btree_au_element, new_key )<br />
<br />
==Parameters==<br />
''btree_au_element''<br />
: A ''struct lfds710_btree_au_element'', which is not currently part of a tree. Not a pointer to it - the struct itself.<br />
<br />
''new_key''<br />
: A pointer, which will be cast by the macro to a ''void *'', which the key in ''btree_au_element'' is set to.<br />
<br />
==Return Value==<br />
No return value.<br />
<br />
==Notes==<br />
The key can only be set before an element enters the btree. If it is set after, the btree will likely be broken (as the new key, being different to the old key, would most likely require the element to be in a different position in the tree, and this element movement is not supported) and also, key is not set atomically, so that even if a change was made, there is in principle no guarantee any other logical core would see that change anyway.<br />
<br />
Key is not set atomically because it is known it will only be set before an element enters the tree. Matters can be (and have been) arranged to ensure key is despite the lack of an atomic set correctly propagated to other logical cores, but this is a behaviour of the linking code, not of the macro which sets key.<br />
<br />
As with all ''liblfds'' macros, the macro operates on the structure itself, not a pointer to it.<br />
<br />
==Example==<br />
#include <stdio.h><br />
#include "liblfds710.h"<br />
<br />
struct test_data<br />
{<br />
int long long unsigned<br />
unique_id;<br />
<br />
char<br />
payload[64];<br />
<br />
struct lfds710_btree_au_element<br />
buae;<br />
};<br />
<br />
int key_compare_function( void const *new_key, void const *existing_key )<br />
{<br />
int<br />
cr = 0;<br />
<br />
int long long unsigned<br />
*new_key = (int long long unsigned *) new_key,<br />
*existing_key = (int long long unsigned *) existing_key;<br />
<br />
if( *new_key > *existing_key )<br />
cr = 1;<br />
<br />
if( *new_key < *existing_key )<br />
cr = -1;<br />
<br />
return( cr );<br />
}<br />
<br />
int main()<br />
{<br />
struct lfds710_btree_au_element<br />
*buae;<br />
<br />
struct lfds710_btree_au_state<br />
baus;<br />
<br />
struct lfds710_misc_prng_state<br />
ps;<br />
<br />
struct test_data<br />
td = { 15, "Tellurium-128" },<br />
*temp_td;<br />
<br />
lfds710_misc_library_init_valid_on_current_logical_core();<br />
<br />
lfds710_misc_prng_init( &ps );<br />
<br />
lfds710_btree_au_init_valid_on_current_logical_core( &baus, key_compare_function, LFDS710_BTREE_AU_EXISTING_KEY_FAIL, NULL );<br />
<br />
LFDS710_BTREE_AU_SET_KEY_IN_ELEMENT( td.baue, &td.unique_id );<br />
LFDS710_BTREE_AU_SET_VALUE_IN_ELEMENT( td.baue, &td );<br />
lfds710_btree_au_link( baus, &td.baue, NULL, &ps );<br />
<br />
lfds710_btree_au_get_by_position( &baus, &baue, LFDS710_BTREE_AU_ROOT );<br />
<br />
temp_td = LFDS710_BTREE_AU_GET_VALUE_FROM_ELEMENT( *baue );<br />
<br />
printf( "payload in element is \"%s\"\n", temp_td->payload );<br />
<br />
lfds710_btree_au_cleanup( &baus );<br />
<br />
lfds710_misc_library_cleanup();<br />
<br />
return( EXIT_SUCCESS );<br />
}<br />
<br />
==See Also==<br />
* [[r7.1.0:Binary Tree (add-only, unbalanced)|Binary Tree (add-only, unbalanced)]]</div>Admin