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

add RangeMap.__mul__ and tests #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add RangeMap.__mul__ and tests #86

wants to merge 1 commit into from

Conversation

werenike
Copy link
Contributor

@werenike werenike commented Apr 6, 2018

Ability to take the product of two RangeMaps, merging their keys and creating tuples from their values.

def test_product():
	rm1 = RangeMap.from_iterable((
		(None, 10, 'a'),
		(10, 25, 'b'),
		))
	rm2 = RangeMap.from_iterable((
		(5, 15, 'c'),
		(15, 25, 'd'),
		(30, None, 'e'),
		))
	assert rm1 * rm2 == RangeMap.from_iterable((
		(None, 5, ('a', None)),
		(5, 10, ('a', 'c')),
		(10, 15, ('b', 'c')),
		(15, 25, ('b', 'd')),
		(30, None, (None, 'e')),
		))
	rm3 = RangeMap.from_iterable((
		(None, 0, 'f'),
		(0, 20, 'g'),
		(35, 40, 'h'),
		))
	assert rm1 * rm2 * rm3 == RangeMap.from_iterable((
		(None, 0, ('a', None, 'f')),
		(0, 5, ('a', None, 'g')),
		(5, 10, ('a', 'c', 'g')),
		(10, 15, ('b', 'c', 'g')),
		(15, 20, ('b', 'd', 'g')),
		(20, 25, ('b', 'd', None)),
		(30, 35, (None, 'e', None)),
		(35, 40, (None, 'e', 'h')),
		(40, None, (None, 'e', None)),
		))

Not sure if the implementation is the best. The class ValueTuple is used to merge tuples of values in products of more than two RangeMaps. Let me know about possibilities for improvement!

@coveralls
Copy link

coveralls commented Apr 6, 2018

Coverage Status

Coverage increased (+0.06%) to 98.023% when pulling d82fe03 on MareinK:rangemap-prod into 84db5bc on mlenzen:master.

@werenike werenike changed the title Rangemap prod add RangeMap.__mul__ and tests Apr 6, 2018
@mlenzen
Copy link
Owner

mlenzen commented Apr 14, 2018

This is an interesting idea. Regarding implementation, I've been thinking about making RangeMap return views of the underlying data instead of copies (#76). I think that implementation could also be used for this. Since the view would know how many RangeMaps were underlying when each tuple value is created, we wouldn't have to do the nesting and flattening.

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

Successfully merging this pull request may close these issues.

3 participants