Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit ddc16d8

Browse files
committed
feat(utils): Add datatype bundle object array
1 parent 77d7a9b commit ddc16d8

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

utils/BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ cc_library(
3737
"@entangled//common/model:transaction",
3838
],
3939
)
40+
41+
cc_library(
42+
name = "bundle_array",
43+
srcs = ["bundle_array.h"],
44+
deps = [
45+
"@com_github_uthash//:uthash",
46+
"@entangled//common/model:bundle",
47+
],
48+
)

utils/bundle_array.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (C) 2019 BiiLabs Co., Ltd. and Contributors
3+
* All Rights Reserved.
4+
* This is free software; you can redistribute it and/or modify it under the
5+
* terms of the MIT license. A copy of the license can be found in the file
6+
* "LICENSE" at the root of this distribution.
7+
*/
8+
9+
#ifndef UTILS_BUNDLE_ARRAY_H_
10+
#define UTILS_BUNDLE_ARRAY_H_
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
#include "common/model/bundle.h"
17+
#include "utarray.h"
18+
19+
/**
20+
* @file bundle_array.h
21+
* @brief Implementation of bundle array object. This object would be used when we fetch multiple
22+
* `bundle_transactions_t` objects. It provides an easier way to save and traverse all the bundles.
23+
*/
24+
25+
typedef UT_array bundle_array_t;
26+
27+
static UT_icd bundle_array_icd = {sizeof(bundle_transactions_t), 0, 0, 0};
28+
29+
/**
30+
* Allocate memory of bundle_array_t
31+
*/
32+
static inline void bundle_array_new(bundle_array_t **const bundle_array) {
33+
utarray_new(*bundle_array, &bundle_array_icd);
34+
}
35+
36+
/**
37+
* @brief The bundle array iterator.
38+
*/
39+
#define BUNDLE_ARRAY_FOREACH(bundles, bdl) \
40+
for (bdl = (bundle_transactions_t *)utarray_front(bundles); bdl != NULL; \
41+
bdl = (bundle_transactions_t *)utarray_next(bundles, bdl))
42+
43+
/**
44+
* Free memory of bundle_array_t
45+
*/
46+
static inline void bundle_array_free(bundle_array_t **const bundle_array) {
47+
// TODO set dtor and use utarray_free() instead.
48+
if (bundle_array && *bundle_array) {
49+
bundle_transactions_t *bundle = NULL;
50+
iota_transaction_t *tx = NULL;
51+
BUNDLE_ARRAY_FOREACH(*bundle_array, bundle) { bundle_transactions_free(&bundle); }
52+
free(*bundle_array);
53+
}
54+
*bundle_array = NULL;
55+
}
56+
57+
#ifdef __cplusplus
58+
}
59+
#endif
60+
61+
#endif // UTILS_BUNDLE_ARRAY_H_

utils/pow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
#define UTILS_POW_H_
1111

1212
#include <stdint.h>
13-
#include "./utarray.h"
1413
#include "accelerator/errors.h"
1514
#include "common/model/bundle.h"
1615
#include "common/trinary/flex_trit.h"
16+
#include "utarray.h"
1717

1818
#ifdef __cplusplus
1919
extern "C" {

0 commit comments

Comments
 (0)