Skip to content

[std.algorithm.setops] cartesianReduction #10935

@crazymonkyyy

Description

@crazymonkyyy

I suggest the inclusion of this code:

auto cartesianReduction(alias F,alias Vinit,alias Hinit,R1,R2,E)(R1 r1,R2 r2,E seed){
	auto r=cartesianProduct(r1,r2);
	alias R=typeof(r);
	E[] storage; storage.reserve(r2.length);
	foreach(e;r2.map!Vinit){
		storage~=e;
	}
	struct range{
		R r;
		E diagonal;
		E[] storage;
		int i;
		auto front()=>F(r.front[0],r.front[1],diagonal,storage[i],i==0?Hinit(r.front[0]):storage[i-1]);
		void popFront(){
			if(i>0){
				diagonal=storage[i];
			}
			storage[i]=front;
			i++;
			if(i==storage.length){
				diagonal=Hinit(r.front);
				i=0;
			}
			r.popFront;
		}
		bool empty()=>r.empty;
	}
	return range(r,seed,storage);
}

ai conversation: https://gemini.google.com/share/614e0ef1a71b with phoboes-ifyed code block

the ai is being very stupid deleting the seed parameter, and it expanding 30 lines into 200 lines but that looks like phobos style to me.


Gentrification of the 3 "smith-waterman" algorithms, following the preexisting cartisianProduct naming

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions