Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aug_seq #4

Open
imoldfella opened this issue Nov 27, 2019 · 0 comments
Open

aug_seq #4

imoldfella opened this issue Nov 27, 2019 · 0 comments

Comments

@imoldfella
Copy link

An augmented sequence might be useful to add:

	template <class entry>
	struct aug_seq_full_entry : entry {
		using val_t = bool; // not used
		using key_t = typename entry::key_t;
		using aug_t = typename entry::aug_t;
		using entry_t = key_t;
		static bool comp(const key_t& a, const key_t& b) { return true; }
		static inline key_t get_key(const entry_t& e) { return e; }
		static inline val_t get_val(const entry_t& e) { return 0; }
		static inline void set_val(entry_t& e, const val_t& v) {}
	};

	template<class _Entry, class Balance=weight_balanced_tree>
	using aug_seq =
		aug_map_< aug_set_full_entry<_Entry>,
			typename Balance::template
			balance<aug_node<typename Balance::data, aug_set_full_entry<_Entry>>>>;

	void test_aug_seq()
	{
		struct piece_entry 
		{
			using key_t = string_view;
			using aug_t = size_t;
			static aug_t get_empty() { return 0; }
			static aug_t from_entry(key_t k) { return k.size(); }
			static aug_t combine(aug_t a, aug_t b) { return a + b; }
		};
		using piece_seq = aug_seq<piece_entry>;

		using strv = piece_seq; //pam_seq<string_view>;

		strv x1;
		strv v1 = strv(string_view("hello, world"));
		strv v2 = strv(string_view("; wassup"));
		strv v3 = strv::join2(v1, v2);

		strv::foreach_seq(v3, [&](auto x) {
			cout << "- " << x << "\n";
			});
		cout << "\n total=" << v3.aug_val() << "\n";
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant