Revision d99e397d

View differences:

som/ChunkIDSet/Makefile
1 1
BASE = ../..
2 2

  
3
OBJS = chunkids_ops.o chunkids_encoding.o
3
OBJS = chunkids_ops.o chunkids_ha.o chunkids_encoding.o
4 4

  
5 5
all: libsignalling.a
6 6

  
som/ChunkIDSet/chunkids_ha.c
1
/*
2
 *  Copyright (c) 2010 Luca Abeni
3
 *
4
 *  This is free software; see lgpl-2.1.txt
5
 */
6

  
7
#include <stdlib.h>
8
#include <stdint.h>
9
#include <limits.h>
10
#include <assert.h>
11

  
12
#include "chunkidset.h"
13

  
14
int chunkID_set_get_earliest(const struct chunkID_set *h)
15
{
16
  int i, min;
17

  
18
  min = INT_MAX;
19
  for (i = 0; i < chunkID_set_size(h); i++) {
20
    int c = chunkID_set_get_chunk(h, i);
21

  
22
    min = (c < min) ? c : min;
23
  }
24

  
25
  return min;
26
}
27

  
28
int chunkID_set_get_latest(const struct chunkID_set *h)
29
{
30
  int i, max;
31

  
32
  max = INT_MIN;
33
  for (i = 0; i < chunkID_set_size(h); i++) {
34
    int c = chunkID_set_get_chunk(h, i);
35

  
36
    max = (c > max) ? c : max;
37
  }
38

  
39
  return max;
40
}
41

  
42
int chunkID_set_union(struct chunkID_set *h, struct chunkID_set *a)
43
{
44
  int i;
45

  
46
  for (i = 0; i < chunkID_set_size(a); i++) {
47
    int ret = chunkID_set_add_chunk(h, chunkID_set_get_chunk(a, i));
48
    if (ret < 0) return ret;
49
  }
50

  
51
  return chunkID_set_size(h);
52
}
som/ChunkIDSet/chunkids_ops.c
109 109
  return -1;
110 110
}
111 111

  
112
int chunkID_set_get_earliest(const struct chunkID_set *h)
113
{
114
  int i, min;
115

  
116
  min = INT_MAX;
117
  for (i = 0; i < h->n_elements; i++) {
118
    min = (h->elements[i] < min) ? h->elements[i] : min;
119
  }
120

  
121
  return min;
122
}
123

  
124
int chunkID_set_get_latest(const struct chunkID_set *h)
125
{
126
  int i, max;
127

  
128
  max = INT_MIN;
129
  for (i = 0; i < h->n_elements; i++) {
130
    max = (h->elements[i] > max) ? h->elements[i] : max;
131
  }
132

  
133
  return max;
134
}
135

  
136
int chunkID_set_union(struct chunkID_set *h, struct chunkID_set *a)
137
{
138
  int i;
139

  
140
  for (i = 0; i < a->n_elements; i++) {
141
    int ret = chunkID_set_add_chunk(h,a->elements[i]);
142
    if (ret < 0) return ret;
143
  }
144
  return h->n_elements;
145
}
146

  
147 112
void chunkID_set_clear(struct chunkID_set *h, int size)
148 113
{
149 114
  h->n_elements = 0;

Also available in: Unified diff