File: archer_query_table.c

package info (click to toggle)
bow 19991122-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,544 kB
  • ctags: 2,987
  • sloc: ansic: 38,660; lisp: 1,072; makefile: 594; perl: 492; yacc: 149; sh: 91
file content (135 lines) | stat: -rw-r--r-- 2,773 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <bow/libbow.h>
#include <bow/archer.h>
#include <bow/archer_query.h>
#include <bow/archer_query_array.h>

extern bow_sarray *archer_docs;


void archer_query_table_invert(bow_array **table)
{
  int i;
  int len = archer_docs->array->length;

  for (i = 0; i < len; ++i)
    if (table[i])
    {
      bow_array_free(table[i]);
      table[i] = NULL;
    }
    else
      table[i] = bow_array_new(0, sizeof(archer_query_word_occurence), 
			       archer_query_array_free_wo);
}

void archer_query_table_empty(bow_array **table)
{
  int i;
  int len = archer_docs->array->length;

  for (i = 0; i < len; ++i)
    if (table[i])
    {
      bow_array_free(table[i]);
      table[i] = NULL;
    }
}

bow_array *archer_query_table_to_bow_array_with_freeing(bow_array **table)
{
  int i;
  int len = archer_docs->array->length;
  archer_query_result aqr;
  bow_array *ret = bow_array_new(0, sizeof(archer_query_result), 
				 archer_query_array_free_result);

  for (i = 0; i < len; ++i)
    if (table[i])
    {
      aqr.di = i;
      aqr.wo = table[i];
      bow_array_append(ret, &aqr);
    }

  free(table); 

  return ret;
}

bow_array **archer_query_table_new(void)
{
  int len = archer_docs->array->length;
  int space = len * sizeof(bow_array *);
  bow_array **new = (bow_array **) bow_malloc(space);
  
  memset(new, 0, space);
  return new;
}

void archer_query_table_free(bow_array **table)
{
  int i;
  int len = archer_docs->array->length;

  for (i = 0; i < len; ++i)
    if (table[i])
      bow_array_free(table[i]);

  free(table);
}

static bow_array *archer_query_table_copy_wo(bow_array *wo_array)
{
    int i, j;
    int len = wo_array->length;
    archer_query_word_occurence *wo, new;
    bow_array *ret = bow_array_new(len, sizeof(archer_query_word_occurence), 
				   archer_query_array_free_wo);

    for (i = 0; i < wo_array->length; ++i)
    {
	wo = bow_array_entry_at_index(wo_array, i);
	new = *wo;

	new.pi = bow_array_new(wo->pi->length, sizeof(int), NULL);
	for (j = 0; j < wo->pi->length; ++j)
	    bow_array_append(new.pi, bow_array_entry_at_index(wo->pi, j));
	
	bow_array_append(ret, &new);
    }

    return ret;
}

bow_array **archer_query_table_copy(bow_array **table)
{
    int i;
    int len = archer_docs->array->length;
    bow_array **new = archer_query_table_new();
    
    for (i = 0; i < len; ++i)
	if (table[i])
	    new[i] = archer_query_table_copy_wo(table[i]);

    return new;
}

/*
void archer_query_table_add(bow_array **table, int index, bow_array *wo)
{
  int len = archer_docs->array->length;
  bow_array *old;

  assert(index >= 0 && index < len);
  old = table[index];

  if (old)
  {
    table[index] = merge_wo(old, wo);
    bow_array_free(wo);
    bow_array_free(old);
  }
  else
    table[index] = wo;
}
*/