Search Manager

In many cases, there will be a need to search one element from a large predefined array, such as getting an element from a lookup table. To simplify such implementation, RAPIDSEA provides a search manager that can be used to find elements from an array quickly using different algorithms such a linear or binary searches.

To use the search manager, use the rs_search_mgr_init function to set the type of search algorithm and the comparison mechanism to be used to find if it is a match. Then configure the lookup array using the rs_search_mgr_config_buffer by indicting the starting address of the array, number of elements in it, size of each element in the array and finally the offset of the member to be compared inside each element. Once this is done, rs_search_mgr_get_element can be used to find the element by passing the address to the search value against which the element is returned, if found.

Search Manager Header

Documentation from the relevant header as follows:

Definitions for RAPIDSEA Search Manager to manage finding data.

Defines

RS_SEARCH_MGR_TYPE_LOOP

Searched in a loop. Slow.

RS_SEARCH_MGR_TYPE_BINARY

Buffer used to hold a list of points array.

RS_SEARCH_MGR_COMPARE_UINT8

Unsigned 8-bit comparison.

Typedefs

typedef struct __rs_search_mgr rs_search_mgr_t

Structure to hold search information.

Functions

rs_ret_val_t rs_search_mgr_init(rs_search_mgr_t *ptr_mgr, uint8_t u8_search_type, uint8_t u8_compare_type)

Initializes the search manager.

This function initializes the given manager for further operation

Initializes the search manager.

Parameters:
  • ptr_mgr[in] - Pointer to the search manager memory

  • u8_search_type[in] - Type of search algorithm to be employed

  • u8_compare_type[in] - Method to compare the elements

Returns:

Zero for success or negative error code

rs_ret_val_t rs_search_mgr_config_buffer(rs_search_mgr_t *ptr_mgr, void *ptr_mem, uint32_t u32_num_elements, uint32_t u32_element_size, uint32_t u32_compare_offset)

Configures the search manager with necessary information.

This function configures the manager with the pointer to search data, number of elements etc

Parameters:
  • ptr_mgr[in] - Pointer to the search manager

  • ptr_mem[in] - Pointer to the array containing the element to search from

  • u32_num_elements[in] - Number of elements in the array

  • u32_element_size[in] - Size of each array element in bytes

  • u32_compare_offset[in] - Offset to the element to be compared in bytes

Returns:

Zero for success or negative error code

void *rs_search_mgr_get_element(rs_search_mgr_t *ptr_mgr, void *ptr_value)

Searches the search manager.

This function searches the given value in return the pointer to the matching element

Parameters:
  • ptr_mgr[in] - Pointer to the search manager

  • ptr_value[in] - Value to search for

Returns:

Pointer to matching element on success or NULL, if no match

struct __rs_search_mgr
#include <rs_search_mgr.h>

Structure to hold search information.

Public Members

uint8_t search_type

Type of search.

uint8_t compare_type

How to compare the values.

uint8_t reserved1

Reserved.

uint8_t reserved2

Reserved.

uint32_t num_elements

Number of elements.

uint32_t element_size

Size of each element.

uint32_t compare_offset

Offset inside element to compare for.

void *ptr_buffer

Pointer to memory region.