Skip to content

Commit

Permalink
Merge pull request #6 from adgear/PEDSP-2941
Browse files Browse the repository at this point in the history
Changes for Erlang Scheduler friendly implementation
  • Loading branch information
vs-ads authored Mar 18, 2024
2 parents 033b51c + e9ba08f commit d5b8bdd
Show file tree
Hide file tree
Showing 8 changed files with 778 additions and 10 deletions.
496 changes: 496 additions & 0 deletions src/ast.c

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ bool match_node(const struct betree_variable** preds,
struct memoize* memoize,
struct report* report);

bool match_node_counting(const struct betree_variable** preds,
const struct ast_node* node,
struct memoize* memoize,
struct report_counting* report);

struct value_bound get_variable_bound(
const struct attr_domain* domain, const struct ast_node* node);

Expand Down
25 changes: 24 additions & 1 deletion src/betree.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ bool betree_insert(struct betree* tree, betree_sub_t id, const char* expr)
return betree_insert_with_constants(tree, id, 0, NULL, expr);
}

static const struct betree_variable** make_environment(size_t attr_domain_count, const struct betree_event* event)
const struct betree_variable** make_environment(size_t attr_domain_count, const struct betree_event* event)
{
const struct betree_variable** preds = bcalloc(attr_domain_count * sizeof(*preds));
for(size_t i = 0; i < event->variable_count; i++) {
Expand Down Expand Up @@ -624,6 +624,29 @@ void free_report(struct report* report)
bfree(report);
}

struct report_counting* make_report_counting()
{
struct report_counting* report = bcalloc(sizeof(*report));
if(report == NULL) {
fprintf(stderr, "%s bcalloc failed\n", __func__);
abort();
}
report->evaluated = 0;
report->matched = 0;
report->memoized = 0;
report->shorted = 0;
report->subs = NULL;
report->node_count = 0;
report->ops_count = 0;
return report;
}

void free_report_counting(struct report_counting* report)
{
bfree(report->subs);
bfree(report);
}

static void betree_init_with_config(struct betree* betree, struct config* config)
{
betree->config = config;
Expand Down
15 changes: 15 additions & 0 deletions src/betree.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ struct report {
betree_sub_t* subs;
};

struct report_counting {
size_t evaluated;
size_t matched;
size_t memoized;
size_t shorted;
betree_sub_t* subs;
int node_count;
int ops_count;
};

struct betree_sub;
struct betree_constant;
struct betree_variable;
Expand Down Expand Up @@ -73,6 +83,8 @@ struct betree_variable_definition {
enum betree_value_type_e type;
};

const struct betree_variable** make_environment(size_t attr_domain_count, const struct betree_event* event);

/*
* Initialization
*/
Expand Down Expand Up @@ -129,6 +141,9 @@ bool betree_exists_with_event(const struct betree* betree, struct betree_event*
struct report* make_report();
void free_report(struct report* report);

struct report_counting* make_report_counting();
void free_report_counting(struct report_counting* report);

/*
* Destruction
*/
Expand Down
67 changes: 67 additions & 0 deletions src/special.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,39 @@ bool within_frequency_caps(const struct betree_frequency_caps* caps,
int64_t now)
{
for(size_t i = 0; i < caps->size; i++) {
const struct betree_frequency_cap* content = caps->content[i];
if(content->id == id &&
content->namespace.str == namespace.str &&
content->type == type) {
if(length <= 0) {
return value > content->value;
}
if(!content->timestamp_defined) {
return true;
}
if((now - (content->timestamp / 1000000)) > (int64_t)length) {
return true;
}
if(value > content->value) {
return true;
}
return false;
}
}
return true;
}

bool within_frequency_caps_counting(const struct betree_frequency_caps* caps,
enum frequency_type_e type,
uint32_t id,
const struct string_value namespace,
uint32_t value,
size_t length,
int64_t now,
int* ops_count)
{
for(size_t i = 0; i < caps->size; i++) {
(*ops_count)++;
const struct betree_frequency_cap* content = caps->content[i];
if(content->id == id &&
content->namespace.str == namespace.str &&
Expand Down Expand Up @@ -54,6 +87,23 @@ bool segment_within(
return false;
}

bool segment_within_counting(
int64_t segment_id, int32_t after_seconds, const struct betree_segments* segments, int64_t now,
int* ops_count)
{
for(size_t i = 0; i < segments->size; i++) {
(*ops_count)++;
if(segments->content[i]->id < segment_id) {
continue;
}
if(segments->content[i]->id == segment_id) {
return (now - after_seconds) <= (segments->content[i]->timestamp / 1000000);
}
return false;
}
return false;
}

bool segment_before(
int64_t segment_id, int32_t before_seconds, const struct betree_segments* segments, int64_t now)
{
Expand All @@ -69,6 +119,23 @@ bool segment_before(
return false;
}

bool segment_before_counting(
int64_t segment_id, int32_t before_seconds, const struct betree_segments* segments, int64_t now,
int* ops_count)
{
for(size_t i = 0; i < segments->size; i++) {
(*ops_count)++;
if(segments->content[i]->id < segment_id) {
continue;
}
if(segments->content[i]->id == segment_id) {
return (now - before_seconds) > (segments->content[i]->timestamp / 1000000);
}
return false;
}
return false;
}

#define EARTH_RADIUS 6372.8
#define TO_RAD (3.1415926536 / 180)

Expand Down
13 changes: 13 additions & 0 deletions src/special.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,23 @@ bool within_frequency_caps(const struct betree_frequency_caps* caps,
uint32_t value,
size_t length,
int64_t now);
bool within_frequency_caps_counting(const struct betree_frequency_caps* caps,
enum frequency_type_e type,
uint32_t id,
const struct string_value namespace,
uint32_t value,
size_t length,
int64_t now, int* ops_count);
bool segment_within(
int64_t segment_id, int32_t after_seconds, const struct betree_segments* segments, int64_t now);
bool segment_within_counting(
int64_t segment_id, int32_t after_seconds, const struct betree_segments* segments, int64_t now,
int* ops_count);
bool segment_before(
int64_t segment_id, int32_t before_seconds, const struct betree_segments* segments, int64_t now);
bool segment_before_counting(
int64_t segment_id, int32_t before_seconds, const struct betree_segments* segments, int64_t now,
int* ops_count);
bool geo_within_radius(double lat1, double lon1, double lat2, double lon2, double distance);
bool contains(const char* value, const char* pattern);
bool starts_with(const char* value, const char* pattern);
Expand Down
Loading

0 comments on commit d5b8bdd

Please sign in to comment.