mirror of
https://github.com/zinchenko291/os-course.git
synced 2026-09-12 20:09:58 +05:00
Modify dedup algo
This commit is contained in:
parent
55322da42d
commit
ff4b7a094e
25
.github/workflows/vtkm.yml
vendored
25
.github/workflows/vtkm.yml
vendored
@ -1,25 +0,0 @@
|
||||
# name: Test VT Kernel Module
|
||||
|
||||
# on:
|
||||
# push:
|
||||
# branches:
|
||||
# - main
|
||||
# pull_request:
|
||||
# paths:
|
||||
# - 'lab/vtkm/**'
|
||||
|
||||
# jobs:
|
||||
# build:
|
||||
# runs-on: ubuntu-latest
|
||||
# defaults:
|
||||
# run:
|
||||
# working-directory: ./lab/vtkm
|
||||
# steps:
|
||||
# - uses: actions/checkout@v4
|
||||
# - name: Clang Format
|
||||
# run: |
|
||||
# find . -path ./build -prune -o \
|
||||
# \( -iname '*.c' -o -iname '*.h' -o -iname '*.cpp' -o -iname '*.hpp' \) \
|
||||
# -exec clang-format --style=file --dry-run --verbose {} \;
|
||||
# - name: Build
|
||||
# run: make
|
||||
54
.github/workflows/vtpc.yml
vendored
54
.github/workflows/vtpc.yml
vendored
@ -1,54 +0,0 @@
|
||||
# name: Test VT Page Cache
|
||||
|
||||
# on:
|
||||
# push:
|
||||
# branches:
|
||||
# - main
|
||||
# pull_request:
|
||||
# paths:
|
||||
# - 'lab/vtpc/**'
|
||||
|
||||
# jobs:
|
||||
# build:
|
||||
# strategy:
|
||||
# matrix:
|
||||
# cmake_build_type:
|
||||
# - Asan
|
||||
# - Release
|
||||
# runs-on: ubuntu-latest
|
||||
# container:
|
||||
# image: silkeh/clang:latest
|
||||
# defaults:
|
||||
# run:
|
||||
# working-directory: ./lab/vtpc
|
||||
# steps:
|
||||
# - name: Checkout
|
||||
# uses: actions/checkout@v4
|
||||
|
||||
# - name: Clang Format
|
||||
# run: |
|
||||
# find . -path ./build -prune -o \
|
||||
# \( -iname '*.c' -o -iname '*.h' -o -iname '*.cpp' -o -iname '*.hpp' \) \
|
||||
# -exec clang-format --style=file --dry-run --verbose {} \;
|
||||
|
||||
# - name: Configure
|
||||
# run: cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }}
|
||||
|
||||
# - name: Build
|
||||
# run: cmake --build build
|
||||
|
||||
# - name: Clang Tidy
|
||||
# if: matrix.cmake_build_type == 'Release'
|
||||
# run: |
|
||||
# find . -path ./build -prune -o \
|
||||
# \( -iname '*.c' -o -iname '*.h' -o -iname '*.cpp' -o -iname '*.hpp' \) -exec \
|
||||
# clang-tidy -p ./build {} \;
|
||||
|
||||
# - name: Test Basic
|
||||
# run: ./build/test/test_basic
|
||||
|
||||
# - name: Test Sequential
|
||||
# run: ./build/test/test_seq
|
||||
|
||||
# - name: Test Random
|
||||
# run: ./build/test/test_random
|
||||
@ -1,14 +1,7 @@
|
||||
#include "cpu_utils.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int cmp_int32(const void* a, const void* b) {
|
||||
int32_t ia = *(const int32_t*)a;
|
||||
int32_t ib = *(const int32_t*)b;
|
||||
return (ia > ib) - (ia < ib);
|
||||
}
|
||||
|
||||
long dedup_run(
|
||||
long size,
|
||||
long max_value,
|
||||
@ -30,17 +23,30 @@ long dedup_run(
|
||||
if (!arr) {
|
||||
return -1;
|
||||
}
|
||||
int32_t* dedup = malloc((size_t)size * sizeof(int32_t));
|
||||
if (!dedup) {
|
||||
free(arr);
|
||||
return -1;
|
||||
}
|
||||
for (long i = 0; i < size; ++i) {
|
||||
arr[i] = (int32_t)(rand_r(seed) % max_value);
|
||||
}
|
||||
qsort(arr, (size_t)size, sizeof(int32_t), cmp_int32);
|
||||
long unique = 0;
|
||||
for (long i = 0; i < size; ++i) {
|
||||
if (i == 0 || arr[i] != arr[i - 1]) {
|
||||
++unique;
|
||||
int32_t value = arr[i];
|
||||
int found = 0;
|
||||
for (long j = 0; j < unique; ++j) {
|
||||
if (dedup[j] == value) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
dedup[unique++] = value;
|
||||
}
|
||||
}
|
||||
free(arr);
|
||||
free(dedup);
|
||||
results[r] = unique;
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
CC=gcc
|
||||
CFLAGS=-O0 -std=c11
|
||||
CFLAGS=-O0
|
||||
|
||||
all: cpu_dedup cpu_dedup_pthreads ema_replace_str ema_replace_str_pthreads
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user