IDZEBRA  2.2.7
Data Structures | Typedefs | Functions | Variables
rsmultiandor.c File Reference

This module implements the rsmulti_or and rsmulti_and result sets. More...

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <idzebra/util.h>
#include <idzebra/isamc.h>
#include <rset.h>

Go to the source code of this file.

Data Structures

struct  heap_item
 
struct  heap
 
struct  rset_private
 
struct  rfd_private
 

Typedefs

typedef struct heapHEAP
 

Functions

static RSFD r_open_and (RSET ct, int flag)
 
static RSFD r_open_or (RSET ct, int flag)
 
static void r_close (RSFD rfd)
 
static void r_delete (RSET ct)
 
static int r_read_and (RSFD rfd, void *buf, TERMID *term)
 reads one item key from an 'and' set More...
 
static int r_read_or (RSFD rfd, void *buf, TERMID *term)
 reads one item key from an 'or' set More...
 
static int r_forward_and (RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
 
static int r_forward_or (RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
 
static void r_pos_and (RSFD rfd, double *current, double *total)
 
static void r_pos_or (RSFD rfd, double *current, double *total)
 
static void r_get_terms (RSET ct, TERMID *terms, int maxterms, int *curterm)
 
static void heap_swap (HEAP h, int x, int y)
 
static int heap_cmp (HEAP h, int x, int y)
 
static int heap_empty (HEAP h)
 
static void heap_delete (HEAP h)
 deletes the first item in the heap, and balances the rest More...
 
static void heap_balance (HEAP h)
 puts item into heap. The heap root element has changed value (to bigger) Swap downwards until the heap is ordered again More...
 
static void heap_insert (HEAP h, struct heap_item *hi)
 
static HEAP heap_create (NMEM nmem, int size, const struct rset_key_control *kctrl)
 
static void heap_clear (HEAP h)
 
static void heap_destroy (HEAP h)
 
int compare_ands (const void *x, const void *y)
 compare and items for quicksort used in qsort to get the multi-and args in optimal order that is, those with fewest occurrences first More...
 
static RSET rsmulti_andor_create (NMEM nmem, struct rset_key_control *kcontrol, int scope, TERMID termid, int no_rsets, RSET *rsets, const struct rset_control *ctrl)
 
RSET rset_create_or (NMEM nmem, struct rset_key_control *kcontrol, int scope, TERMID termid, int no_rsets, RSET *rsets)
 
RSET rset_create_and (NMEM nmem, struct rset_key_control *kcontrol, int scope, int no_rsets, RSET *rsets)
 
static RSFD r_open_andor (RSET ct, int flag, int is_and)
 
static void r_pos_x (RSFD rfd, double *current, double *total, int and_op)
 

Variables

static const struct rset_control control_or
 
static const struct rset_control control_and
 
static int log_level = 0
 
static int log_level_initialized = 0
 

Detailed Description

This module implements the rsmulti_or and rsmulti_and result sets.

rsmultior is based on a heap, from which we find the next hit.

rsmultiand is based on a simple array of rsets, and a linear search to find the record that exists in all of those rsets. To speed things up, the array is sorted so that the smallest rsets come first, they are most likely to have the hits furthest away, and thus forwarding to them makes the most sense.

Definition in file rsmultiandor.c.

Typedef Documentation

◆ HEAP

typedef struct heap* HEAP

Definition at line 108 of file rsmultiandor.c.

Function Documentation

◆ compare_ands()

int compare_ands ( const void *  x,
const void *  y 
)

compare and items for quicksort used in qsort to get the multi-and args in optimal order that is, those with fewest occurrences first

Definition at line 240 of file rsmultiandor.c.

References heap_item::fd, and rset_pos.

Referenced by r_open_andor().

◆ heap_balance()

static void heap_balance ( HEAP  h)
static

puts item into heap. The heap root element has changed value (to bigger) Swap downwards until the heap is ordered again

Definition at line 176 of file rsmultiandor.c.

References heap_cmp(), and heap_swap().

Referenced by r_forward_or(), and r_read_or().

◆ heap_clear()

static void heap_clear ( HEAP  h)
static

Definition at line 225 of file rsmultiandor.c.

References heap::heapnum.

Referenced by r_open_andor().

◆ heap_cmp()

static int heap_cmp ( HEAP  h,
int  x,
int  y 
)
static

Definition at line 140 of file rsmultiandor.c.

References heap_item::buf, rset_key_control::cmp, heap::heap, and heap::kctrl.

Referenced by heap_balance(), heap_delete(), and heap_insert().

◆ heap_create()

static HEAP heap_create ( NMEM  nmem,
int  size,
const struct rset_key_control kctrl 
)
static

Definition at line 212 of file rsmultiandor.c.

References heap::heap, heap::heapmax, heap::heapnum, and heap::kctrl.

Referenced by r_open_andor().

◆ heap_delete()

static void heap_delete ( HEAP  h)
static

deletes the first item in the heap, and balances the rest

Definition at line 152 of file rsmultiandor.c.

References heap::heap, heap_cmp(), heap_swap(), and heap::heapnum.

Referenced by r_forward_or(), and r_read_or().

◆ heap_destroy()

static void heap_destroy ( HEAP  h)
static

Definition at line 231 of file rsmultiandor.c.

Referenced by r_close().

◆ heap_empty()

static int heap_empty ( HEAP  h)
static

Definition at line 145 of file rsmultiandor.c.

References heap::heapnum.

Referenced by r_forward_or(), and r_read_or().

◆ heap_insert()

static void heap_insert ( HEAP  h,
struct heap_item hi 
)
static

Definition at line 194 of file rsmultiandor.c.

References heap::heap, heap_cmp(), heap_swap(), and heap::heapnum.

Referenced by r_open_andor().

◆ heap_swap()

static void heap_swap ( HEAP  h,
int  x,
int  y 
)
static

Definition at line 132 of file rsmultiandor.c.

References heap::heap.

Referenced by heap_balance(), heap_delete(), and heap_insert().

◆ r_close()

static void r_close ( RSFD  rfd)
static

◆ r_delete()

static void r_delete ( RSET  ct)
static

Definition at line 287 of file rsmultiandor.c.

◆ r_forward_and()

static int r_forward_and ( RSFD  rfd,
void *  buf,
TERMID term,
const void *  untilbuf 
)
static

◆ r_forward_or()

static int r_forward_or ( RSFD  rfd,
void *  buf,
TERMID term,
const void *  untilbuf 
)
static

◆ r_get_terms()

static void r_get_terms ( RSET  ct,
TERMID terms,
int  maxterms,
int *  curterm 
)
static

◆ r_open_and()

static RSFD r_open_and ( RSET  ct,
int  flag 
)
static

Definition at line 362 of file rsmultiandor.c.

References r_open_andor().

◆ r_open_andor()

static RSFD r_open_andor ( RSET  ct,
int  flag,
int  is_and 
)
static

◆ r_open_or()

static RSFD r_open_or ( RSET  ct,
int  flag 
)
static

Definition at line 357 of file rsmultiandor.c.

References r_open_andor().

◆ r_pos_and()

static void r_pos_and ( RSFD  rfd,
double *  current,
double *  total 
)
static

Definition at line 642 of file rsmultiandor.c.

References r_pos_x().

◆ r_pos_or()

static void r_pos_or ( RSFD  rfd,
double *  current,
double *  total 
)
static

Definition at line 647 of file rsmultiandor.c.

References r_pos_x().

◆ r_pos_x()

static void r_pos_x ( RSFD  rfd,
double *  current,
double *  total,
int  and_op 
)
static

◆ r_read_and()

static int r_read_and ( RSFD  rfd,
void *  buf,
TERMID term 
)
static

reads one item key from an 'and' set

Parameters
rfdset handle
bufresulting item buffer
termresulting term
Return values
0EOF
1item could be read

Has to return all hits where each item points to the same sysno (scope), in order. Keep an extra key (hitkey) as long as all records do not point to hitkey, forward them, and update hitkey to be the highest seen so far. (if any item eof's, mark eof, and return 0 thereafter) Once a hit has been found, scan all items for the smallest value. Mark all as being in the tail. Read next from that item, and if not in the same record, clear its tail bit

Definition at line 452 of file rsmultiandor.c.

References heap_item::buf, rset_key_control::cmp, rfd_private::eof, heap_item::fd, rset_key_control::get_segment, rfd_private::hits, rfd_private::items, rset_key_control::key_size, rset::keycontrol, rset::no_children, rsfd::priv, rsfd::rset, rset_forward, rset_read, rset::scope, rfd_private::segment, rfd_private::skip, rfd_private::tailbits, rfd_private::tailcount, and heap_item::term.

Referenced by r_forward_and().

◆ r_read_or()

static int r_read_or ( RSFD  rfd,
void *  buf,
TERMID term 
)
static

reads one item key from an 'or' set

Parameters
rfdset handle
bufresulting item buffer
termresulting term
Return values
0EOF
1item could be read

Definition at line 409 of file rsmultiandor.c.

References heap_item::buf, heap_item::fd, rfd_private::h, heap::heap, heap_balance(), heap_delete(), heap_empty(), rfd_private::hits, rset_key_control::key_size, rset::keycontrol, rsfd::priv, rsfd::rset, rset_read, rset::term, and heap_item::term.

Referenced by r_forward_or().

◆ rset_create_and()

RSET rset_create_and ( NMEM  nmem,
struct rset_key_control kcontrol,
int  scope,
int  no_rsets,
RSET rsets 
)

◆ rset_create_or()

RSET rset_create_or ( NMEM  nmem,
struct rset_key_control kcontrol,
int  scope,
TERMID  termid,
int  no_rsets,
RSET rsets 
)

◆ rsmulti_andor_create()

static RSET rsmulti_andor_create ( NMEM  nmem,
struct rset_key_control kcontrol,
int  scope,
TERMID  termid,
int  no_rsets,
RSET rsets,
const struct rset_control ctrl 
)
static

Variable Documentation

◆ control_and

const struct rset_control control_and
static
Initial value:
=
{
"multi-and",
}
int rset_no_write(RSFD rfd, const void *buf)
Definition: rset.c:431
static void r_pos_and(RSFD rfd, double *current, double *total)
Definition: rsmultiandor.c:642
static int r_forward_and(RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
Definition: rsmultiandor.c:559
static void r_get_terms(RSET ct, TERMID *terms, int maxterms, int *curterm)
Definition: rsmultiandor.c:652
static RSFD r_open_and(RSET ct, int flag)
Definition: rsmultiandor.c:362
static void r_delete(RSET ct)
Definition: rsmultiandor.c:287
static int r_read_and(RSFD rfd, void *buf, TERMID *term)
reads one item key from an 'and' set
Definition: rsmultiandor.c:452
static void r_close(RSFD rfd)
Definition: rsmultiandor.c:367

Definition at line 59 of file rsmultiandor.c.

Referenced by rset_create_and().

◆ control_or

const struct rset_control control_or
static
Initial value:
=
{
"multi-or",
}
static RSFD r_open_or(RSET ct, int flag)
Definition: rsmultiandor.c:357
static int r_forward_or(RSFD rfd, void *buf, TERMID *term, const void *untilbuf)
Definition: rsmultiandor.c:379
static int r_read_or(RSFD rfd, void *buf, TERMID *term)
reads one item key from an 'or' set
Definition: rsmultiandor.c:409
static void r_pos_or(RSFD rfd, double *current, double *total)
Definition: rsmultiandor.c:647

Definition at line 59 of file rsmultiandor.c.

Referenced by rset_create_or().

◆ log_level

int log_level = 0
static

Definition at line 127 of file rsmultiandor.c.

Referenced by r_pos_x(), and rsmulti_andor_create().

◆ log_level_initialized

int log_level_initialized = 0
static

Definition at line 128 of file rsmultiandor.c.

Referenced by rsmulti_andor_create().