summaryrefslogtreecommitdiff
path: root/ot_vector.h
blob: 8d4145219ec14bc35a71cf3021c2a94d4f7d9cbd (plain)
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
/* This software was written by Dirk Engling <erdgeist@erdgeist.org>
   It is considered beerware. Prost. Skol. Cheers or whatever.

   $id$ */

#ifndef OT_VECTOR_H__
#define OT_VECTOR_H__

/* These defines control vectors behaviour */
#define OT_VECTOR_MIN_MEMBERS   2
#define OT_VECTOR_GROW_RATIO    2
#define OT_VECTOR_SHRINK_THRESH 4
#define OT_VECTOR_SHRINK_RATIO  2

#define OT_PEER_BUCKET_MINCOUNT 512
#define OT_PEER_BUCKET_MAXCOUNT 256

typedef struct {
  void  *data;
  size_t size;
  size_t space;
} ot_vector;

void    *binary_search(const void *const key, const void *base, const size_t member_count, const size_t member_size, size_t compare_size, int *exactmatch);
void    *vector_find_or_insert(ot_vector *vector, void *key, size_t member_size, size_t compare_size, int *exactmatch);
ot_peer *vector_find_or_insert_peer(ot_vector *vector, ot_peer const *peer, size_t peer_size, int *exactmatch);

int      vector_remove_peer(ot_vector *vector, ot_peer const *peer, size_t peer_size);
void     vector_remove_torrent(ot_vector *vector, ot_torrent *match);

/* For ot_clean.c */
void     vector_redistribute_buckets(ot_peerlist *peer_list, size_t peer_size);
void     vector_fixup_peers(ot_vector *vector, size_t peer_size);
void     vector_clean_list(ot_vector *vector, int num_buckets);

#endif