~mkas/mixxx/mysql

« back to all changes in this revision

Viewing changes to mixxx/lib/xwax/lut.cpp

  • Committer: MKas
  • Date: 2012-11-03 12:55:54 UTC
  • Revision ID: mkas@tux.lt-20121103125554-ez5ajqyk7bwehrp2
merge with trunk + sql fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2010 Mark Hills <mark@pogo.org.uk>
 
2
 * Copyright (C) 2012 Mark Hills <mark@pogo.org.uk>
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or
5
5
 * modify it under the terms of the GNU General Public License
34
34
/* Initialise an empty hash lookup table to store the given number
35
35
 * of timecode -> position lookups */
36
36
 
37
 
int lut_init(struct lut_t *lut, int nslots)
 
37
int lut_init(struct lut *lut, int nslots)
38
38
{
39
39
    int n, hashes;
40
40
    size_t bytes;
41
41
 
42
42
    hashes = 1 << HASH_BITS;
43
 
    bytes = sizeof(struct slot_t) * nslots + sizeof(slot_no_t) * hashes;
 
43
    bytes = sizeof(struct slot) * nslots + sizeof(slot_no_t) * hashes;
44
44
 
45
45
    fprintf(stderr, "Lookup table has %d hashes to %d slots"
46
46
            " (%d slots per hash, %zuKb)\n",
47
47
            hashes, nslots, nslots / hashes, bytes / 1024);
48
48
 
49
 
    lut->slot = (struct slot_t*)malloc(sizeof(struct slot_t) * nslots);
 
49
    lut->slot = (struct slot*)malloc(sizeof(struct slot) * nslots);
50
50
    if (lut->slot == NULL) {
51
51
        perror("malloc");
52
52
        return -1;
67
67
}
68
68
 
69
69
 
70
 
void lut_clear(struct lut_t *lut)
 
70
void lut_clear(struct lut *lut)
71
71
{
72
72
    free(lut->table);
 
73
    free(lut->slot);
73
74
}
74
75
 
75
76
 
76
 
void lut_push(struct lut_t *lut, unsigned int timecode)
 
77
void lut_push(struct lut *lut, unsigned int timecode)
77
78
{
78
79
    unsigned int hash;
79
80
    slot_no_t slot_no;
80
 
    struct slot_t *slot;
 
81
    struct slot *slot;
81
82
 
82
83
    slot_no = lut->avail++; /* take the next available slot */
83
84
 
90
91
}
91
92
 
92
93
 
93
 
unsigned int lut_lookup(struct lut_t *lut, unsigned int timecode)
 
94
unsigned int lut_lookup(struct lut *lut, unsigned int timecode)
94
95
{
95
96
    unsigned int hash;
96
97
    slot_no_t slot_no;
97
 
    struct slot_t *slot;
 
98
    struct slot *slot;
98
99
 
99
100
    hash = HASH(timecode);
100
101
    slot_no = lut->table[hash];