Statistics
| Branch: | Revision:

grapes / som / ChunkIDSet / chunkids_ha.c @ d99e397d

History | View | Annotate | Download (920 Bytes)

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
}