-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
505 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.decl numbers(x:number) | ||
.decl sum_result(x:number) | ||
.decl hsum_result(x:number) | ||
.output sum_result() | ||
.output hsum_result() | ||
.functor hashsum(i1:number, i2:number):number stateful | ||
|
||
numbers(-1). | ||
numbers(1). | ||
numbers(2). | ||
numbers(3). | ||
numbers(4). | ||
numbers(5). | ||
|
||
sum_result(x) :- | ||
x = sum a : { numbers(a), a > 0 }. | ||
|
||
hsum_result(x) :- | ||
x = @@hashsum a : 0, { numbers(a), a > 0 }. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "souffle/SouffleFunctor.h" | ||
#include "souffle/utility/MiscUtil.h" | ||
#include <cassert> | ||
|
||
#if RAM_DOMAIN_SIZE == 64 | ||
using FF_int = int64_t; | ||
using FF_uint = uint64_t; | ||
using FF_float = double; | ||
#else | ||
using FF_int = int32_t; | ||
using FF_uint = uint32_t; | ||
using FF_float = float; | ||
#endif | ||
|
||
extern "C" { | ||
souffle::RamDomain hashsum(souffle::SymbolTable* symbolTable, souffle::RecordTable* recordTable, | ||
souffle::RamDomain arg1, souffle::RamDomain arg2); | ||
unsigned long djb2(const std::string &str); | ||
} | ||
|
||
souffle::RamDomain hashsum(souffle::SymbolTable* symbolTable, souffle::RecordTable* recordTable, souffle::RamDomain arg1, souffle::RamDomain arg2) { | ||
assert(symbolTable && "NULL symbol table"); | ||
assert(recordTable && "NULL record table"); | ||
|
||
std::string result = std::to_string(arg1 + djb2(std::to_string(arg2))); | ||
return arg1 + djb2(std::to_string(arg2)); | ||
} | ||
|
||
unsigned long djb2(const std::string &str) { | ||
unsigned long hash = 5381; // Initialize hash with a prime number | ||
for (char c : str) { | ||
// Multiply hash by 33 and add the current character | ||
hash = ((hash << 5) + hash) + c; // hash * 33 + c | ||
} | ||
return hash; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "souffle/SouffleFunctor.h" | ||
#include "souffle/utility/MiscUtil.h" | ||
#include <cassert> | ||
|
||
#if RAM_DOMAIN_SIZE == 64 | ||
using FF_int = int64_t; | ||
using FF_uint = uint64_t; | ||
using FF_float = double; | ||
#else | ||
using FF_int = int32_t; | ||
using FF_uint = uint32_t; | ||
using FF_float = float; | ||
#endif | ||
|
||
extern "C" { | ||
souffle::RamDomain lub(souffle::SymbolTable* symbolTable, souffle::RecordTable* recordTable, | ||
souffle::RamDomain i1, souffle::RamDomain i2); | ||
souffle::RamDomain lub_number(souffle::SymbolTable* symbolTable, souffle::RecordTable* recordTable, | ||
souffle::RamDomain i, souffle::RamDomain x); | ||
} | ||
|
||
souffle::RamDomain lub(souffle::SymbolTable*, souffle::RecordTable* recordTable, souffle::RamDomain i1, | ||
souffle::RamDomain i2) { | ||
const souffle::RamDomain* interval1 = recordTable->unpack(i1, 2); | ||
const souffle::RamDomain* interval2 = recordTable->unpack(i2, 2); | ||
auto lb = std::min(interval1[0], interval2[0]); | ||
auto ub = std::max(interval1[1], interval2[1]); | ||
const souffle::RamDomain res[2] = {lb, ub}; | ||
return recordTable->pack(res, 2); | ||
} | ||
|
||
souffle::RamDomain lub_number(souffle::SymbolTable*, souffle::RecordTable* recordTable, souffle::RamDomain i, | ||
souffle::RamDomain x) { | ||
const souffle::RamDomain* interval = recordTable->unpack(i, 2); | ||
auto lb = std::min(interval[0], x); | ||
auto ub = std::max(interval[1], x); | ||
const souffle::RamDomain res[2] = {lb, ub}; | ||
return recordTable->pack(res, 2); | ||
} |
Oops, something went wrong.