changing to STL deque

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2023-07-18 03:57:31 +02:00
parent 36d098cea3
commit 5faca2220a
No known key found for this signature in database
GPG Key ID: 0FE274EE8C95166E
3 changed files with 49 additions and 1 deletions

32
DAS/deque.cc Normal file
View File

@ -0,0 +1,32 @@
#include <deque>
#include "pybind11/pybind11.h"
#include "pybind11/stl.h"
namespace py = pybind11;
using std::deque;
struct DequeInt {
deque<int16_t> 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_<DequeInt>(m, "DequeInt")
.def(py::init<>())
.def("append", &DequeInt::push)
.def("popleft", &DequeInt::pop)
.def("empty", &DequeInt::empty)
.def("__bool__", &DequeInt::notEmpty);
}

View File

@ -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:

15
Makefile Normal file
View File

@ -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