ston initial
[henge/apc.git] / src / henge.h
1 /*!@file
2 \brief HENGE Memory Definition in common with STON Asset Packages
3 \details C Aligned memory structures used to define datatypes in the STON
4 Asset Package format, used for reading asset packages as runtime
5 memory.
6 \author Ken Grimes
7 \date Feb 2017
8 ----------------------------------------------------------------------------*/
9 #ifndef _HENGE_H_
10 #define _HENGE_H_
11
12 /* Henge Generic Hashtable
13
14 Hashtables are stored as dynamically sized two dimensional arrays, whose
15 columns are provided, and whose rows, and sizes, are derived.
16
17 ht_size = header.ht_columns << header.ht_2pow;
18 ht_rows = 0x1 << header.ht_2pow;
19
20 All generic hashtables in henge must have a power-of-two number of rows. An
21 ht_columns value that is also a power-of-two will result in a power-of-two
22 sized memory imprint for the structure, making it easy to page align.
23
24 Elements in the columns may be of any arbitrary size.
25
26 typedef uint32_t my_ht_type;
27 ht_bytes = ht_size * sizeof(my_ht_type);
28 */
29 struct hng_ht_header_t
30 { uint16_t ht_columns;
31 uint8_t ht_2pow, ht_flags;
32 };
33
34 #define hng_ht_size(_HEADER) ((_HEADER)->ht_columns << (_HEADER)->ht_2pow)
35 #define hng_ht_rows(_HEADER) (0x1 << (_HEADER)->ht_2pow)
36 #define hng_ht_cols(_HEADER) (_HEADER->ht_columns)
37 #define hng_ht_start(_HEADER) (_HEADER + sizeof(*_HEADER))
38 #define hng_ht_array(_HEADER,_UNIT) ((_UNIT*)hng_ht_start(_HEADER))
39 #define hng_ht_bytes(_HEADER,_UNIT) (hng_ht_size(_HEADER) * sizeof(_UNIT))
40 #define hng_ht_2bytes(_HEADER,_UNIT2POW) (hng_ht_size(_HEADER) << _UNIT2POW)
41
42 #endif //_HENGE_H_