aboutsummaryrefslogtreecommitdiff
path: root/tests/performance/15_shuffle0.sy
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.001@gmail.com>2026-09-15 08:16:43 +0800
committerRichard Qin <richard.qin.001@gmail.com>2026-09-15 08:16:43 +0800
commit4022e5c95210631e4aceb08eaf9d9071aa5aefc4 (patch)
treea5922559836e45fb3459a3d070367912e1035b1a /tests/performance/15_shuffle0.sy
downloadrcc-master.tar.gz
rcc-master.tar.xz
Set up a git repoHEADmaster
Diffstat (limited to 'tests/performance/15_shuffle0.sy')
-rw-r--r--tests/performance/15_shuffle0.sy93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/performance/15_shuffle0.sy b/tests/performance/15_shuffle0.sy
new file mode 100644
index 0000000..1500f4c
--- /dev/null
+++ b/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;
+}