src/cx/tree.h

changeset 890
54565fd74e74
parent 871
e29c1f96646d
equal deleted inserted replaced
889:f549fd9fbd8f 890:54565fd74e74
319 * 319 *
320 * @return 0 if the node contains the data, 320 * @return 0 if the node contains the data,
321 * positive if one of the children might contain the data, 321 * positive if one of the children might contain the data,
322 * negative if neither the node, nor the children contains the data 322 * negative if neither the node, nor the children contains the data
323 */ 323 */
324 typedef int (*cx_tree_search_data_func)(void const *node, void const *data); 324 typedef int (*cx_tree_search_data_func)(const void *node, const void *data);
325 325
326 326
327 /** 327 /**
328 * Function pointer for a search function. 328 * Function pointer for a search function.
329 * 329 *
346 * 346 *
347 * @return 0 if \p node contains the same data as \p new_node, 347 * @return 0 if \p node contains the same data as \p new_node,
348 * positive if one of the children might contain the data, 348 * positive if one of the children might contain the data,
349 * negative if neither the node, nor the children contains the data 349 * negative if neither the node, nor the children contains the data
350 */ 350 */
351 typedef int (*cx_tree_search_func)(void const *node, void const *new_node); 351 typedef int (*cx_tree_search_func)(const void *node, const void *new_node);
352 352
353 /** 353 /**
354 * Searches for data in a tree. 354 * Searches for data in a tree.
355 * 355 *
356 * When the data cannot be found exactly, the search function might return a 356 * When the data cannot be found exactly, the search function might return a
373 * could contain the node (but doesn't right now), negative if the tree does not 373 * could contain the node (but doesn't right now), negative if the tree does not
374 * contain any node that might be related to the searched data 374 * contain any node that might be related to the searched data
375 */ 375 */
376 __attribute__((__nonnull__)) 376 __attribute__((__nonnull__))
377 int cx_tree_search_data( 377 int cx_tree_search_data(
378 void const *root, 378 const void *root,
379 void const *data, 379 const void *data,
380 cx_tree_search_data_func sfunc, 380 cx_tree_search_data_func sfunc,
381 void **result, 381 void **result,
382 ptrdiff_t loc_children, 382 ptrdiff_t loc_children,
383 ptrdiff_t loc_next 383 ptrdiff_t loc_next
384 ); 384 );
406 * could contain the node (but doesn't right now), negative if the tree does not 406 * could contain the node (but doesn't right now), negative if the tree does not
407 * contain any node that might be related to the searched data 407 * contain any node that might be related to the searched data
408 */ 408 */
409 __attribute__((__nonnull__)) 409 __attribute__((__nonnull__))
410 int cx_tree_search( 410 int cx_tree_search(
411 void const *root, 411 const void *root,
412 void const *node, 412 const void *node,
413 cx_tree_search_func sfunc, 413 cx_tree_search_func sfunc,
414 void **result, 414 void **result,
415 ptrdiff_t loc_children, 415 ptrdiff_t loc_children,
416 ptrdiff_t loc_next 416 ptrdiff_t loc_next
417 ); 417 );
477 * created node or \c NULL when allocation fails. 477 * created node or \c NULL when allocation fails.
478 * 478 *
479 * \note the function may leave the node pointers in the struct uninitialized. 479 * \note the function may leave the node pointers in the struct uninitialized.
480 * The caller is responsible to set them according to the intended use case. 480 * The caller is responsible to set them according to the intended use case.
481 */ 481 */
482 typedef void *(*cx_tree_node_create_func)(void const *, void *); 482 typedef void *(*cx_tree_node_create_func)(const void *, void *);
483 483
484 /** 484 /**
485 * The local search depth for a new subtree when adding multiple elements. 485 * The local search depth for a new subtree when adding multiple elements.
486 * The default value is 3. 486 * The default value is 3.
487 * This variable is used by #cx_tree_add_array() and #cx_tree_add_iter() to 487 * This variable is used by #cx_tree_add_array() and #cx_tree_add_iter() to
578 * @return the number of array elements successfully processed 578 * @return the number of array elements successfully processed
579 * @see cx_tree_add() 579 * @see cx_tree_add()
580 */ 580 */
581 __attribute__((__nonnull__(1, 4, 5, 7, 8))) 581 __attribute__((__nonnull__(1, 4, 5, 7, 8)))
582 size_t cx_tree_add_array( 582 size_t cx_tree_add_array(
583 void const *src, 583 const void *src,
584 size_t num, 584 size_t num,
585 size_t elem_size, 585 size_t elem_size,
586 cx_tree_search_func sfunc, 586 cx_tree_search_func sfunc,
587 cx_tree_node_create_func cfunc, 587 cx_tree_node_create_func cfunc,
588 void *cdata, 588 void *cdata,
640 * @return zero when a new node was created and added to the tree, 640 * @return zero when a new node was created and added to the tree,
641 * non-zero otherwise 641 * non-zero otherwise
642 */ 642 */
643 __attribute__((__nonnull__(1, 2, 3, 5, 6))) 643 __attribute__((__nonnull__(1, 2, 3, 5, 6)))
644 int cx_tree_add( 644 int cx_tree_add(
645 void const *src, 645 const void *src,
646 cx_tree_search_func sfunc, 646 cx_tree_search_func sfunc,
647 cx_tree_node_create_func cfunc, 647 cx_tree_node_create_func cfunc,
648 void *cdata, 648 void *cdata,
649 void **cnode, 649 void **cnode,
650 void *root, 650 void *root,

mercurial