aboutsummaryrefslogtreecommitdiff
path: root/rcc-legacy/tests/performance/15_shuffle0.sy
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-06-08 17:10:31 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-06-08 17:10:31 +0800
commit72af0dedf9e18911da65b9a5c4906689e868d9fc (patch)
tree2ecbad93f96ab8ad7e26dc02cd02d802f853ab97 /rcc-legacy/tests/performance/15_shuffle0.sy
parent8faf6d290d6703b1775e0ad7a8928a4ebea4b11b (diff)
downloadrcc-project-72af0dedf9e18911da65b9a5c4906689e868d9fc.tar.gz
rcc-project-72af0dedf9e18911da65b9a5c4906689e868d9fc.tar.xz
[legacy] Add functional and performance test suites
Diffstat (limited to 'rcc-legacy/tests/performance/15_shuffle0.sy')
-rw-r--r--rcc-legacy/tests/performance/15_shuffle0.sy93
1 files changed, 93 insertions, 0 deletions
diff --git a/rcc-legacy/tests/performance/15_shuffle0.sy b/rcc-legacy/tests/performance/15_shuffle0.sy
new file mode 100644
index 0000000..1500f4c
--- /dev/null
+++ b/rcc-legacy/tests/performance/15_shuffle0.sy
@@ -0,0 +1,93 @@
+int hashmod;
+
+const int maxn = 10000000;
+const int maxm = 10000000;
+int bucket[maxn];
+int head[maxn];
+int next[maxm];
+int nextvalue[maxm];
+int key[maxm];
+int value[maxm];
+int cnt;
+
+int keys[maxm];
+int values[maxm];
+int requests[maxm];
+int ans[maxm];
+
+int hash(int k){
+ return k % hashmod;
+}
+
+int insert(int k, int v){
+ int h = hash(k);
+ if (head[h] == 0){
+ cnt = cnt + 1;
+ head[h] = cnt;
+ key[cnt] = k;
+ value[cnt] = v;
+ next[cnt] = 0;
+ nextvalue[cnt] = 0;
+ return 0;
+ }
+ int p = head[h];
+ while (p != 0){
+ if (key[p] == k){
+ cnt = cnt + 1;
+ nextvalue[cnt] = nextvalue[p];
+ nextvalue[p] = cnt;
+ value[cnt] = v;
+ return 1;
+ }
+ p = next[p];
+ }
+ cnt = cnt + 1;
+ next[cnt] = head[h];
+ head[h] = cnt;
+ key[cnt] = k;
+ value[cnt] = v;
+ nextvalue[cnt] = 0;
+ return 0;
+}
+
+int reduce(int k){
+ int h = hash(k);
+ int p = head[h];
+
+ while (p != 0){
+ if (key[p] == k){
+ int ret = 0;
+ int x = p;
+ while (x != 0){
+ ret = ret + value[x];
+ x = nextvalue[x];
+ }
+ return ret;
+ }
+ p = next[p];
+ }
+ return 0;
+}
+
+int main(){
+ hashmod = getint();
+ int ks = getarray(keys);
+ int vs = getarray(values);
+ int ms = getarray(requests);
+
+ starttime();
+
+ int i = 0;
+ while (i < ks){
+ insert(keys[i], values[i]);
+ i = i + 1;
+ }
+ i = 0;
+ while (i < ms){
+ ans[i] = reduce(requests[i]);
+ i = i + 1;
+ }
+ stoptime();
+ putarray(ms, ans);
+ return 0;
+}