Example ProgramsΒΆ
The example shows how to use HCL data structures. The template can be used for any data structure supported by HCL.
1#include <hcl.h>
2
3int main(int argc, char *argv[]) {
4 bool is_server = true;
5 if (argc == 1) {
6 fprintf(stderr, "call `executable <server>`\n");
7 exit(1);
8 }
9 if (argc > 1) is_server = atoi(argv[1]);
10 size_t my_server = 0;
11 size_t num_servers = 1;
12 bool server_on_node = false;
13 auto hcl =
14 hcl::HCL::GetInstance(true, 10000, num_servers, my_server, 0, is_server,
15 server_on_node, "", "./server_list");
16 auto map = hcl::unordered_map<int, int>();
17 if (is_server) {
18 fprintf(stderr, "Press any key to exit server\n");
19 fflush(stdout);
20 getchar();
21 fprintf(stderr, "Finished server\n");
22 } else {
23 for (int i = 0; i < 128; i++) {
24 auto result = map.Put(i, i);
25 assert(result);
26 }
27 fprintf(stderr, "Finished client\n");
28 }
29 hcl->Finalize();
30 exit(EXIT_SUCCESS);
31}
The test shows an end to end usage of hcl within an application. To run this test, we have two components server and client which can switched using args.
To run the server
simple_test 1
This will start a server and host the hcl data structure on that process.
Then run a client which can access this data structure,
simple_test 0