From 5faca2220abdf026547a27df1e522f459a09ba2f Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Tue, 18 Jul 2023 03:57:31 +0200 Subject: [PATCH] changing to STL deque Signed-off-by: Csaba Kiraly --- DAS/deque.cc | 32 ++++++++++++++++++++++++++++++++ DAS/validator.py | 3 ++- Makefile | 15 +++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 DAS/deque.cc create mode 100644 Makefile diff --git a/DAS/deque.cc b/DAS/deque.cc new file mode 100644 index 0000000..fc57a62 --- /dev/null +++ b/DAS/deque.cc @@ -0,0 +1,32 @@ + +#include + +#include "pybind11/pybind11.h" +#include "pybind11/stl.h" + +namespace py = pybind11; + +using std::deque; + +struct DequeInt { + deque d; + DequeInt() {} + void push(int e) { d.push_back(e); } + int pop() { + auto ret = d.front(); + d.pop_front(); + return ret; + } + bool empty() {return d.empty();} + bool notEmpty() {return not d.empty();} +}; + +PYBIND11_MODULE(deque, m) { + // m.doc() = "STL based deque"; // optional module docstring + py::class_(m, "DequeInt") + .def(py::init<>()) + .def("append", &DequeInt::push) + .def("popleft", &DequeInt::pop) + .def("empty", &DequeInt::empty) + .def("__bool__", &DequeInt::notEmpty); +} diff --git a/DAS/validator.py b/DAS/validator.py index 2b489b8..be45ff2 100644 --- a/DAS/validator.py +++ b/DAS/validator.py @@ -5,6 +5,7 @@ import collections import logging from DAS.block import * from DAS.tools import shuffled, shuffledDict, unionOfSamples +from DAS.deque import DequeInt from bitarray.util import zeros from collections import deque from itertools import chain @@ -28,7 +29,7 @@ class Neighbor: self.receiving = zeros(blockSize) self.received = zeros(blockSize) self.sent = zeros(blockSize) - self.sendQueue = deque() + self.sendQueue = DequeInt() class Validator: diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f7d0173 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +.PHONY: test clean + +CC := g++ +FLAGS := -Wall -std=c++11 -shared -fPIC +FLAGS += -undefined dynamic_lookup +INC := $(shell python3 -m pybind11 --include) +SUFFIX := $(shell python3-config --extension-suffix) + +CC_FILE := DAS/deque.cc +OBJ := DAS/deque$(SUFFIX) + +$(OBJ): $(CC_FILE) + $(CC) $(FLAGS) $(INC) $< -o $(OBJ) +clean: + rm *.so \ No newline at end of file