Re: Delphi can do map/reduce?
- From: mamcx <this@xxxxxxxxxxxx>
- Date: Fri, 11 Aug 2006 15:34:39 -0500
Dan Downs escribió:
Thanks to both...I don't think Delphi can't, I know I can pass a function but I don't understand this concept enough to solve it myself...
I can think of a couple ways to go about it, but I'm not sure its as eligant as functional languages.
The only real limitation I see is having to hard set your function types and parameter lists and matching your map functions to those so everything matches up correctly. There's a couple ways I can think of to make it a more flexible and dynamic, but I'm not sure its worth the added complexity and unless you were scaling it out to several cpus/systems the extra overhead would probably limit any gain.
If I converted the sample code correctly I think you'd end up with something like the following in delphi.
type
TMapableIntFunc = function( a, b : Integer) : Integer;
TMapableIntFunc = function( a, b : String) : String;
TIntegerArray = array of Integer;
TStringArray = array of String;
function IntReduce(fn : TMapableIntFunc; a : TIntegerArray; init : Integer) : Integer;
var
s, i : Integer;
begin
s := init;
for i := 0 to Length(a)-1 do
s := fn( s, a[i] );
Result := s;
end;
function sumInts(a : TIntegerArray) : Integer;
begin
Result := IntReduce( SumIntFunc, a, 0 );
end;
function StrReduce(fn : TMapableStrFunc; a : TStringArray; init : String) : String;
var
i : Integer;
s : String;
begin
s := init;
for i := 0 to Length(a)-1 do
s := fn( s, a[i] );
Result := s;
end;
function joinStrings(a : TStringArray) : String;
begin
Result := StrReduce( JoinStrFunc, a, "" );
end;
function SumIntFunc(a, b : Integer) : Integer;
begin
Result := a + b;
end;
function JoinStrFunc(a, b : String) : String;
begin
Result := a + b;
end;
By itself this doesn't really do much, but rewritting the IntReduce and StrReduce function to a multithreaded or message disbatching to server farm approach, would make this alot more interesting.
DD
Now I have a starting pont...
Also, other thing I think is embed python and do the map/reduce function on this and passing to delphi???
In the other side, what things are best/cool to have using this?
.
- Follow-Ups:
- Re: Delphi can do map/reduce?
- From: Herbert Sitz
- Re: Delphi can do map/reduce?
- References:
- Delphi can do map/reduce?
- From: mamcx
- Re: Delphi can do map/reduce?
- From: Dan Downs
- Delphi can do map/reduce?
- Prev by Date: Re: Delphi can do map/reduce?
- Next by Date: Re: Borland still losing money...
- Previous by thread: Re: Delphi can do map/reduce?
- Next by thread: Re: Delphi can do map/reduce?
- Index(es):
Relevant Pages
|