rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
fm_select.c File Reference

Keeping the page a bounded list shows while a folder is read, in the caller's order (fm_select.h). More...

#include "fm_select.h"
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

Functions

static void * at (void *set, size_t size, int i)
 Entry i of set.
static int order (fm_rank_fn rank, const void *a, const void *b)
 rank's answer as -1, 0 or 1, so that a sign can turn it round whatever its size.
static int keep_ranked (void *set, size_t size, int count, int capacity, const void *cand, fm_rank_fn rank, int sign)
 The insertion both kinds of page share: sign 1 keeps the entries that rank first, -1 the entries that rank last.
int fm_select_keep (void *set, size_t size, int count, int capacity, const void *cand, fm_rank_fn rank)
 Offer cand to a set of count entries in rank order, which keeps the capacity entries that rank first.
void fm_select_begin (fm_select_t *sel, void *set, size_t size, int capacity, fm_rank_fn rank, fm_page_dir_t dir, const void *key)
 Start choosing one page into set.
void fm_select_offer (fm_select_t *sel, const void *cand)
 Offer one entry of the folder.
int fm_select_end (fm_select_t *sel, fm_rank_fn show, int *ahead)
 End the walk: sort the page for display and say where it stands.

Detailed Description

Keeping the page a bounded list shows while a folder is read, in the caller's order (fm_select.h).

SPDX-License-Identifier: MIT

Function Documentation

◆ at()

void * at ( void * set,
size_t size,
int i )
static

Entry i of set.

Parameters
setthe entries
sizebytes of one entry
ithe index
Returns
its address

◆ fm_select_begin()

void fm_select_begin ( fm_select_t * sel,
void * set,
size_t size,
int capacity,
fm_rank_fn rank,
fm_page_dir_t dir,
const void * key )

Start choosing one page into set.

Parameters
selthe walk's state
setroom for capacity entries of size bytes
sizebytes of one entry
capacityentries set takes
rankthe order the pages run in; strict
dirthe side of key the page holds
keythe entry at the page's edge, or NULL for none; it has to outlive the walk

◆ fm_select_end()

int fm_select_end ( fm_select_t * sel,
fm_rank_fn show,
int * ahead )

End the walk: sort the page for display and say where it stands.

Parameters
selthe walk's state
showthe order the page is drawn in, or NULL for the walk's own order
aheadtakes the count of offered entries that rank ahead of the page's first; may be NULL
Returns
the entries the page holds

◆ fm_select_keep()

int fm_select_keep ( void * set,
size_t size,
int count,
int capacity,
const void * cand,
fm_rank_fn rank )

Offer cand to a set of count entries in rank order, which keeps the capacity entries that rank first.

A candidate that ranks behind a full set is dropped; one that ranks ahead of its last entry takes that entry's place.

Parameters
setthe entries, in rank order
sizebytes of one entry
countentries in set: the last call's answer
capacityroom in set
candthe entry offered; copied when it is kept
rankthe order
Returns
the count after the offer; never above capacity

◆ fm_select_offer()

void fm_select_offer ( fm_select_t * sel,
const void * cand )

Offer one entry of the folder.

Parameters
selthe walk's state
candthe entry; copied when it is kept

◆ keep_ranked()

int keep_ranked ( void * set,
size_t size,
int count,
int capacity,
const void * cand,
fm_rank_fn rank,
int sign )
static

The insertion both kinds of page share: sign 1 keeps the entries that rank first, -1 the entries that rank last.

Parameters
setthe entries, in sign times rank order
sizebytes of one entry
countentries in set
capacityroom in set
candthe entry offered
rankthe order
sign1 or -1
Returns
the count after the offer

◆ order()

int order ( fm_rank_fn rank,
const void * a,
const void * b )
static

rank's answer as -1, 0 or 1, so that a sign can turn it round whatever its size.

Parameters
rankthe order
aan entry
ban entry
Returns
-1, 0 or 1