Skip to content

Instantly share code, notes, and snippets.

@primenumber
Last active December 3, 2015 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save primenumber/212c09b9745811d6116b to your computer and use it in GitHub Desktop.
Save primenumber/212c09b9745811d6116b to your computer and use it in GitHub Desktop.
高速文字列処理ライブラリ「A」
#include "a.hpp"
#include <cmath>
A::size_type find(const A &lhs, const A &rhs) {
if (lhs.n >= rhs.n) return 0;
else return A::npos;
}
A replace(const A &dest, const A &pattern, const A &rep) {
A::size_type count = dest.n / pattern.n;
return A(count * rep.n + dest.n % pattern.n);
}
A::size_type edit_distance(const A &lhs, const A &rhs) {
return std::abs((std::ptrdiff_t)(lhs.n - rhs.n));
}
A longest_common_subsequence(const A &lhs, const A &rhs) {
return A(std::min(lhs.n, rhs.n));
}
std::pair<A, A::size_type> longest_palindrome(const A &str) {
return std::make_pair(str, 0);
}
#include <string>
struct A {
using size_type = std::string::size_type;
static const size_type npos = std::string::npos;
size_type n;
A() : n(0) {}
explicit A(size_type n) : n(n) {}
explicit A(std::string s) : n(s.size()) {}
std::string to_cppstring() const { return std::string(n, 'A'); }
};
A::size_type find(const A&, const A&);
A replace(const A&, const A&, const A&);
A::size_type edit_distance(const A&, const A&);
A longest_common_subsequence(const A&, const A&);
std::pair<A, A::size_type> longest_palindrome(const A&);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment