Statistics
| Branch: | Revision:

grapes / som / ChunkIDSet / chunkids_ha.c @ 438e6c03

History | View | Annotate | Download (1.08 KB)

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 <assert.h>
10

    
11
#include "chunkidset.h"
12

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

    
18
  if (chunkID_set_size(h) == 0) {
19
    return CHUNKID_INVALID;
20
  }
21
  min = chunkID_set_get_chunk(h, 0);
22
  for (i = 1; i < chunkID_set_size(h); i++) {
23
    int c = chunkID_set_get_chunk(h, i);
24

    
25
    min = (c < min) ? c : min;
26
  }
27

    
28
  return min;
29
}
30

    
31
uint32_t chunkID_set_get_latest(const struct chunkID_set *h)
32
{
33
  int i;
34
  uint32_t  max;
35

    
36
  if (chunkID_set_size(h) == 0) {
37
    return CHUNKID_INVALID;
38
  }
39
  max = chunkID_set_get_chunk(h, 0);
40
  for (i = 1; i < chunkID_set_size(h); i++) {
41
    int c = chunkID_set_get_chunk(h, i);
42

    
43
    max = (c > max) ? c : max;
44
  }
45

    
46
  return max;
47
}
48

    
49
int chunkID_set_union(struct chunkID_set *h, struct chunkID_set *a)
50
{
51
  int i;
52

    
53
  for (i = 0; i < chunkID_set_size(a); i++) {
54
    int ret = chunkID_set_add_chunk(h, chunkID_set_get_chunk(a, i));
55
    if (ret < 0) return ret;
56
  }
57

    
58
  return chunkID_set_size(h);
59
}