summaryrefslogtreecommitdiffstats
path: root/katomic/atom.h
blob: 19d9b0874e12cdfbbcf776e2400e3f72bdb1333c (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
#ifndef ATOM_H
#define ATOM_H

#define MAX_CONNS_PER_ATOM 8

class atom {
 public:
    char obj;
    char conn[MAX_CONNS_PER_ATOM + 1];

    bool operator==(const atom& rhs) const { return (rhs.obj == obj && !strcmp(rhs.conn,conn)); }
    bool isEmpty() const { return (obj == 0 || obj == '.'); }
};

inline char int2atom(int i) { 
    if (!i)
	return '.';
    if (i == 254)
	return '#';
    if (i <= 9) 
	return i + '0';
    return i + 'a' - 10;
}

inline int atom2int(char ch) {
    if (ch == '.' || ch == 0)
	return 0;
    if (ch == '#')
	return 254;
    if (ch >= '0' && ch <= '9')
	return ch - '0';
    return ch - 'a' + 10;
}

#endif