function lfds700_stack_query

From liblfds.org
Jump to navigation Jump to search

Source Files

└───liblfds700
    ├───inc
    │   └───liblfds700
    │           lfds700_stack.h
    └───src
        └───lfds700_stack
                lfds700_stack_query.c

Enums

enum lfds700_stack_query
{
  LFDS700_STACK_QUERY_SINGLETHREADED_GET_COUNT,
  LFDS700_STACK_QUERY_SINGLETHREADED_VALIDATE
};

Opaque Structures

struct lfds700_stack_state;

Prototype

void lfds700_stack_query( struct lfds700_stack_state *ss,
                          enum lfds700_stack_query query_type,
                          void *query_input,
                          void *query_output );

Parameters

struct lfds700_stack_state *ss

A pointer to an initialized struct lfds700_stack_state.

enum lfds700_stack_query query_type

Indicates which query to perform.

void *query_input

A pointer to input data for the query, where the data varies by query;
LFDS700_STACK_QUERY_SINGLETHREADED_GET_COUNT
query_input is NULL.
LFDS700_STACK_QUERY_SINGLETHREADED_VALIDATE
query_input can be NULL, or or can be a pointer to a struct lfds700_misc_validation_info, which specifies an expected min/max count, in which case validation also counts the number of elements and check they fall within the specified range.

void *query_output

A pointer to output store for the query, where the output varies by query;
LFDS700_STACK_QUERY_SINGLETHREADED_GET_COUNT
Points to a lfds700_pal_uint_t, which is set to the number of elements in the tree.
LFDS700_STACK_QUERY_SINGLETHREADED_VALIDATE
Points to an enum lfds700_misc_validity, which is set to indicate the result of the validation operation.

Notes

All SINGLETHREADED queries can only be safely performed if no push or pop operations occur while the operation runs. If push or pop operations do occur during the execution of a SINGLETHREADED query, it is theoretically possible for the query to enter an infinite loop. Do not do this.

Example

#include <stdio.h>
#include "liblfds700.h"

int main()
{
  eunm lfds700_misc_validity
    v;

  int long long unsigned
    loop;

  lfds700_pal_uint_t
    element_count;

  struct lfds700_misc_prng_state
    ps;

  struct lfds700_misc_validation_info
    vi;

  struct lfds700_stack_element
    *se;

  struct lfds700_stack_state
    ss;

  lfds700_misc_library_init_valid_on_current_logical_core();

  lfds700_misc_prng_init( &ps );

  lfds700_stack_init_valid_on_current_logical_core( &ss, NULL );

  se = malloc( sizeof(struct lfds700_stack_element) * 10 );

  for( loop = 0 ; loop < 10 ; loop++ )
  {
    LFDS700_STACK_SET_VALUE_IN_ELEMENT( se[loop], (void *) loop );
    lfds700_stack_push( &ss, &se[loop], &ps );
  }

  lfds700_stack_query( &ss, LFDS700_STACK_QUERY_SINGLETHREADED_GET_COUNT, NULL, &element_count );

  printf( "element count = %llu\n", (int long long unsigned) element_count );

  vi.min_elements = 10;
  vi.max_elements = 10;

  lfds700_stack_query( &ss, LFDS700_STACK_QUERY_SINGLETHREADED_VALIDATE, (void *) &vi, (void *) &v );

  if( v == LFDS700_MISC_VALIDITY_VALID )
    printf( "Well thank goodness for that\n" );

  if( v != LFDS700_MISC_VALIDITY_VALID )
    printf( "Oh bugger\n" );

  lfds700_stack_cleanup( &ss, NULL );

  free( se );

  lfds700_misc_library_cleanup();

  return( EXIT_SUCCESS );
}

See Also