Back to index

lightning-sunbird  0.9+nobinonly
Classes | Typedefs | Functions | Variables
gs.c File Reference
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include "rdf-int.h"
#include "gs.h"

Go to the source code of this file.

Classes

struct  _TrieNodeStruct
struct  _TrieTargetStruct

Typedefs

typedef struct _TrieNodeStruct TrieNodeStruct
typedef TrieNodeStructTNS
typedef struct _TrieTargetStruct TrieTargetStruct
typedef TrieTargetStructTTS

Functions

int addTarget (RDFT db, TNS node, RDF_Resource label, RDF_Resource targetNode)
TNS findChildOfChar (TNS node, char c)
TNS findChildOfString (TNS node, char *str)
void RDFGS_AddSearchIndex (RDFT db, char *string, RDF_Resource label, RDF_Resource target)
void countChildren (TNS node, size_t *n, size_t *m)
void fillUpChildren (RDF_Cursor c, TNS node)
RDF_Cursor RDFGS_Search (RDFT db, char *searchString, RDF_Resource label)
void RDFGS_DisposeCursor (RDF_Cursor c)
int alreadyAdded (RDF_Resource node, RDF_Cursor c)
RDF_Resource RDFGS_NextValue (RDF_Cursor c)

Variables

static TNS gRootNode = 0

Class Documentation

struct _TrieNodeStruct

Definition at line 49 of file gs.c.

Collaboration diagram for _TrieNodeStruct:
Class Members
char c
struct _TrieNodeStruct * child
struct _TrieNodeStruct * next
struct _TrieTargetStruct * targets
struct _TrieTargetStruct

Definition at line 58 of file gs.c.

Collaboration diagram for _TrieTargetStruct:
Class Members
RDFT db
RDF_Resource label
struct _TrieTargetStruct * next
RDF_Resource target

Typedef Documentation

typedef TrieNodeStruct* TNS

Definition at line 56 of file gs.c.

Definition at line 65 of file gs.c.


Function Documentation

int addTarget ( RDFT  db,
TNS  node,
RDF_Resource  label,
RDF_Resource  targetNode 
)

Definition at line 70 of file gs.c.

                                                                           {
  TTS target ;
  int n = 0;
  /*  for (target = node->targets; target != null; target = target->next) {
    if (target->target == targetNode) return 0;
    n++;
  } */
  target = (TTS) fgetMem(sizeof(TrieTargetStruct));
  target->next = node->targets;
  node->targets = target;
  target->label = label;
  target->target = targetNode;
  target->db = db;
  return n;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 200 of file gs.c.

                                              {
  int n =0;
  while (c->pdata2[n] && (n < c->off)) {
    if (c->pdata2[n] == node) return 1;
    n++;
  }
  return 0;
}

Here is the caller graph for this function:

void countChildren ( TNS  node,
size_t *  n,
size_t *  m 
)

Definition at line 146 of file gs.c.

                                               {
  TNS ch;
  TTS tg ;
  if (node->targets) (*n)++;
  for (tg = node->targets; tg; tg = tg->next)  (*m)++;
  ch = node->child;
  while (ch) {
    countChildren(ch, n, m);
    ch = ch->next;
  }
}

Here is the caller graph for this function:

void fillUpChildren ( RDF_Cursor  c,
TNS  node 
)

Definition at line 159 of file gs.c.

                                        {
  TNS ch;
  if (node->targets) *((TTS*)c->pdata1 + c->count++) = node->targets;
  ch = node->child;
  while (ch) {
    fillUpChildren(c, ch);
    ch = ch->next;
  }
} 

Here is the caller graph for this function:

TNS findChildOfChar ( TNS  node,
char  c 
)

Definition at line 87 of file gs.c.

                                   {
  TNS ch = node->child;
  char c1 = tolower(c);
  int n = 0;
  while (ch) {
    if (c1 == ch->c) return ch;
    ch = ch->next;
       n++;
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

TNS findChildOfString ( TNS  node,
char *  str 
)

Definition at line 100 of file gs.c.

                                        {
  size_t size = strlen(str);
  size_t n = 0;
  while (n < size) {
    char c = str[n++];
    node = findChildOfChar(node, c);
    if (!node) return 0;
  }
  return node;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void RDFGS_AddSearchIndex ( RDFT  db,
char *  string,
RDF_Resource  label,
RDF_Resource  target 
)

Definition at line 111 of file gs.c.

                                                                                           {
    size_t size = strlen(string);
    size_t n    = 0;
    char* stk = 0;
    TNS    prev, next;
    if (!gRootNode) gRootNode = (TNS) getMem(sizeof(TrieNodeStruct));
    prev = gRootNode;
    next = 0;
    while (n < size) {
       char c = string[n++]; 
       if (!wsCharp(c) && (c != '/')) {
          if (!stk) stk = &string[n-1];
           next = (TNS) findChildOfChar(prev, c);
            if (!next) {
              next = (TNS)fgetMem(sizeof(TrieNodeStruct));
              next->next = prev->child;
              prev->child = next;
              next->c    = tolower(c);
            }
            prev = next;            
       } else if (next) {
           int n = addTarget(db, next, label, target);
            stk = 0;
           prev = gRootNode;
        next = 0;
       }
    }
    if (next)  {
              addTarget(db, next, label, target);
              prev = gRootNode;
        next = 0;
       }
}    

Here is the call graph for this function:

Definition at line 193 of file gs.c.

                                        {
  if (c->pdata1) freeMem(c->pdata1);
  if (c->pdata2) freeMem(c->pdata2);
  freeMem(c);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 209 of file gs.c.

                                            { 
  if (!c->pdata) {
    return 0;
  } else  {
    TTS currentTTS = (TTS) c->pdata;
    while (currentTTS) {
      if (((!c->s) || (c->s == currentTTS->label)) && 
          (!alreadyAdded(currentTTS->target, c))) {
        RDF_Resource ans = currentTTS->target;
        c->pdata = currentTTS = currentTTS->next;
        if (!currentTTS && (c->pdata1)) { 
          c->pdata =  ((TTS*)c->pdata1)[c->count++];  
        }
        if (c->off < c->off1) c->pdata2[c->off++] = ans; 
        return ans;
      }       
      c->pdata = currentTTS =  currentTTS->next;
      if (!currentTTS  && (c->pdata1)) {
        c->pdata = currentTTS = ((TTS*)c->pdata1)[c->count++];  
      }
    }
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

RDF_Cursor RDFGS_Search ( RDFT  db,
char *  searchString,
RDF_Resource  label 
)

Definition at line 170 of file gs.c.

                                                                          {
    RDF_Cursor c = (RDF_Cursor) getMem(sizeof(RDF_CursorStruct));
    size_t n = 0;
    size_t m = 0;
    c->searchString = searchString;
    c->s = label;
    c->db = db;
    c->pdata = findChildOfString(gRootNode, searchString);
    if (!c->pdata) return c;
    countChildren((TNS)c->pdata, &n, &m);
    c->pdata2 = (RDF_Resource*) getMem(sizeof(RDF_Resource) * (m+1)); 
    c->off1 = m;
    if (n > 0) {
      c->count = 0;
      c->pdata1 = getMem(sizeof(TTS) * (n+1));
      fillUpChildren(c, (TNS)c->pdata);
      c->count = 1;
    }
    if (c->pdata) c->pdata = ((TNS)c->pdata)->targets;

    return c;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

TNS gRootNode = 0 [static]

Definition at line 67 of file gs.c.