summaryrefslogtreecommitdiff
path: root/lib/hj/pyutils.h
diff options
context:
space:
mode:
authorLywx <kiritodev01@gmail.com>2023-09-16 04:01:24 -0600
committerGitHub <noreply@github.com>2023-09-16 04:01:24 -0600
commitae8487a4adc5d6d33c47d41e3a40d3c67ddb1e45 (patch)
treee03627371fc7423c684631ed7eee68d697709e0f /lib/hj/pyutils.h
parentf5cbd0056d601e4adaf5ed9006192dd510226ee3 (diff)
parent98b6d598324fdcb499a2cc4d37a7a6fcd19e8ead (diff)
Merge pull request #1 from KiritoDv/feature/audio
Implemented full audio extraction
Diffstat (limited to 'lib/hj/pyutils.h')
-rw-r--r--lib/hj/pyutils.h65
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/hj/pyutils.h b/lib/hj/pyutils.h
new file mode 100644
index 0000000..f34c1d8
--- /dev/null
+++ b/lib/hj/pyutils.h
@@ -0,0 +1,65 @@
+#pragma once
+
+#include <vector>
+#include <unordered_map>
+
+namespace PyUtils {
+template<typename T>
+std::vector<T> slice(std::vector<T> const &v, uint32_t m, uint32_t n = -1) {
+ auto first = v.cbegin() + m;
+ auto last = n == -1 ? v.cend() : v.cbegin() + n;
+
+ std::vector<T> vec(first, last);
+ return vec;
+}
+
+std::vector<uint32_t> range(uint32_t start, uint32_t end);
+
+template<typename T>
+T max(std::vector<T> const &v) {
+ T max = v[0];
+ for (auto const &value: v) {
+ if (value > max) {
+ max = value;
+ }
+ }
+ return max;
+}
+template<typename T>
+T min(std::vector<T> const &v) {
+ T min = v[0];
+ for (auto const &value: v) {
+ if (value < min) {
+ min = value;
+ }
+ }
+ return min;
+}
+
+template<typename T, typename X>
+std::vector<T> keys(std::unordered_map<T, X> const &map) {
+ std::vector<T> result;
+ for (auto const &pair: map) {
+ result.push_back(pair.first);
+ }
+ return result;
+}
+template<typename T, typename X>
+std::vector<T> keys(std::map<T, X> const &map) {
+ std::vector<T> result;
+ for (auto const &pair: map) {
+ result.push_back(pair.first);
+ }
+ return result;
+}
+}
+
+template <typename T>
+std::vector<T> operator+(std::vector<T> const &x, std::vector<T> const &y)
+{
+ std::vector<T> vec;
+ vec.reserve(x.size() + y.size());
+ vec.insert(vec.end(), x.begin(), x.end());
+ vec.insert(vec.end(), y.begin(), y.end());
+ return vec;
+} \ No newline at end of file