# Cursor

> Cursors are used to navigate sets of records returned by index searches with functions `mco_cursor_first(), mco_cursor_last(), mco_cursor_prev()` and ``mco_cursor_next()``. A cursor structure is also used for calls to generated index_cursor functions and `mco_uda_cursor()` Following is the definition of the `mco_cursor_t` structure as defined in `mco.h`:

>         #define mco_cursor_size      (100*sizeof(mco_offs_t))   /* cursor structure size */

>         typedef struct mco_cursor_t_
>         {
>             MCO_PUB_STRUCT_BASE c[mco_cursor_size_w];

>         } mco_cursor_t,  /* cursor (structure)            */
>         *mco_cursor_h; /* cursor handle (pointer)       */

> The array c contains 100 offsets values. These are set to the addresses of database records satisfying a search.

> ## Cursor Types

> Cursors are of different types depending on the type of index they operate on. The following cursor types are defined in `mco.h`:

>         typedef enum MCO_CURSOR_TYPE_E_
>         {
>             MCO_LIST_CURSOR = 0, MCO_TREE_CURSOR = 1,
>             MCO_HASH_CURSOR = 2, MCO_KDTREE_CURSOR = 3,
>             MCO_PTREE_CURSOR = 4, MCO_RTREE_CURSOR = 5

>         } MCO_CURSOR_TYPE;

> MCO_LIST_CURSOR | List (`hash`) index cursor.
> MCO_TREE_CURSOR | `tree` index cursor
> MCO_HASH_CURSOR | `hash` index cursor
> MCO_KDTREE_CURSOR | `kdtree` index cursor
> MCO_PTREE_CURSOR | `patricia` Trie index cursor
> MCO_RTREE_CURSOR | `rtree` index cursor

> ## Cursor Operation Codes

> When calling an index search function to return a cursor, one of the following cursor operator codes (`opcodes`) must be specified:

>         typedef enum MCO_OPCODE_E_
>         {
>             MCO_NOP = 0,  /* No operation */
>             MCO_LT = 1,   /* Values less-than sample */
>             MCO_LE = 2,   /* Values less-or-equal to the sample */
>             MCO_EQ = 3,   /* Values equal to the sample */
>             MCO_GE = 4,   /* Values greater-or-equal to the sample */
>             MCO_GT = 5,   /* Values greater-than the sample */
>             MCO_OVERLAP = 6,  /* rtree, overlapping regions */
>             MCO_CONTAIN = 7,  /* rtree, containing regions */
>             MCO_EX = 8,       /* patricia, exact match */
>             MCO_BEST = 9,     /* patricia, the best, longest match */
>             MCO_PREF = 10,    /* patricia, prefix match */
>             MCO_NEXT_MATCH = 11, /* patricia, continue search instead of new search */
>             MCO_NEIGHBOURHOOD = 12, /* rtree, list object distances from the sample */
>             MCO_NEIGHBORHOOD = MCO_NEIGHBOURHOOD, /* American synonym */
>             MCO_BELONG = MCO_LE /* patricia, sample belongs to value */

>         } MCO_OPCODE;

> MCO_NOP | No Operation
> MCO_LT | Values less-than sample
> MCO_LE | Values less-or-equal to the sample
> MCO_EQ | Values equal to the sample
> MCO_GE | Values greater-than-or-equal-to the sample
> MCO_GT | Values greater-than the sample
> MCO_OVERLAP | `rtree`, overlapping regions
> MCO_CONTAIN | `rtree`, containing regions
> MCO_EX | `patricia`, exact match
> MCO_BEST | `patricia`, the best, longest match
> MCO_PREF | `patricia`, prefix match
> MCO_NEXT_MATCH | `patricia`, continue search instead of new search
> MCO_NEIGHBORHOOD (= MCO_NEIGHBOURHOOD) | `rtree`, list object distances from the sample
> MCO_BELONG (= MCO_LE) | `patricia`, sample belongs to value