-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom_parameter_manager.cc
executable file
·60 lines (45 loc) · 1.71 KB
/
atom_parameter_manager.cc
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
$Id: atom_parameter_manager.cc,v 1.3 2007/05/18 09:40:30 garrett Exp $
AutoDock
Copyright (C) 1989-2007, Michael Pique, Garrett M. Morris, David S. Goodsell, Ruth Huey, Arthur J. Olson,
All Rights Reserved.
AutoDock is a Trade Mark of The Scripps Research Institute.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#define MAXKEY (256*256)
#include <stdlib.h>
#include <string.h>
#include "structs.h" // needed for ParameterEntry structure
#include "atom_parameter_manager.h"
typedef ParameterEntry PE;
static PE *dictionary[MAXKEY];
static unsigned int
hash(const char key[]) {
switch (strlen(key)) {
case 0: return 0;
case 1: return (unsigned int)key[0];
default: return (unsigned int)key[0] + 256*(unsigned int)key[1];
}
}
void
apm_enter(const char key[], PE value) {
if (dictionary[hash(key)] == NULL) {
dictionary[hash(key)] = (PE *) calloc(1, sizeof(PE));
}
*(dictionary[hash(key)]) = value; // this replaces, as well as inserts
return;
}
PE *
apm_find(const char key[]) {
return dictionary[hash(key)];
}