On Saturday, 22 March 2014 at 14:41:48 UTC, Jay Norwood wrote:
The computation times of different methods can differ a lot.
How do you suggest to measure this effectively without the
overhead of the write and writeln output? Would a count of
11 and stubs like below be reasonable, or
Is there a neat way to do this transformation with ranges and
std.algorithms?
Input:
---
B foo
B bar
C ble
B big
A begga
Output: (aggregated and sorted on length)
---
B - [foo, bar, big]
C - [ble]
A - [begga]
The most obvious way (to me)
On Friday, 21 March 2014 at 15:38:23 UTC, bearophile wrote:
Output: (aggregated and sorted on length)
---
B - [foo, bar, big]
C - [ble]
A - [begga]
What is the desired output data structure? An associative array
of dynamic arrays? Or is a dynamic arrays of dynamic arrays of
On Friday, 21 March 2014 at 16:04:45 UTC, bearophile wrote:
I think this problem needs a sorting or a hash. One possible
solution, if you don't need an associative array as output, is
to use a multiSort followed by a building of groups using
slicing. It could be efficient enough. Later you
On Friday, 21 March 2014 at 16:53:46 UTC, H. S. Teoh wrote:
Be aware, though, that groupBy only compares *adjacent*
elements for
equivalence; it does not sort the input. So if your input has
equivalent
elements interspersed with non-equivalent elements, you will
have the
equivalent elements
On Friday, 21 March 2014 at 17:20:38 UTC, Luís Marques wrote:
I think that's why Justin used sort. The hashGroupBy proposed
by bearophile would avoid the sort and the additional memory
usage though, so that would be even better.
I was thinking, we don't even need the full power of sort. Is
On Saturday, 22 March 2014 at 01:08:11 UTC, bearophile wrote:
how is it supposed to know where to group items? Usually you
build an associative array for that.
It would swap elements, like sort, so it doesn't need to put them
anywhere, just permute them. The advantage is this:
Input: [7, 3,
I'm trying to accept delegates or functions in a templated method.
My first try using isDelegate!dg || isFunctionPointer!dg did
not work because isDelegate fails, although I'm not sure I
understand exactly why:
void main()
{
int x;
static assert(isDelegate!(() { x =
On Tuesday, 7 May 2013 at 06:19:24 UTC, Idan Arye wrote:
If it's not templated - make it templated! You don't have to
make the entire `TypeHanler` templated, just the method that
creates it. There, you can create an anonymous function that
receives `Object` and returns `bool` and all it does
In this code:
// accepts a list of handlers, for the respective types
void addHandlers(T...)(T handlers)
{
foreach(handler; handlers)
{
addHandler(handler);
}
}
// accepts one handler, for type T
void addHandler(T)(void delegate (T)
On Friday, 24 May 2013 at 22:37:49 UTC, Luís Marques wrote:
foo.addHandlers(delegate (int x) { /* if no scope access
deduction fails */ });
(I meant that deduction would fail if the literal was not marked
as a delegate)
On Saturday, 25 May 2013 at 00:02:50 UTC, Heinz wrote:
#define my_id 'asdf'
string my_id = asdf;
On Saturday, 25 May 2013 at 00:07:02 UTC, Luís Marques wrote:
On Saturday, 25 May 2013 at 00:02:50 UTC, Heinz wrote:
#define my_id 'asdf'
Ah, sorry, didn't notice the single quotes.
I remember that there was a smarter way to do this, but you can
do it manually. Something like:
immutable long my_id = 'a' 24 + 'b' 16 + 'c' 8 + 'd';
Or you can create a CTFE function to do this from a string, which
should be nicer, if you don't find an existing utility for this.
I have a list of functions which receive values of different
types, like in std.concurrency...
// example from std.concurrency
receive(
(int i) { writeln(Received the number , i);}
);
...although in my case I can probably live by with only accepting
objects.
I built a
On Monday, 6 May 2013 at 21:20:49 UTC, Idan Arye wrote:
BTW, for this to work `typeHandler.type` needs to be known at
compile-time.
That's the rub. This list of handler is dynamic, so
`typeHandler.type` is a TypeInfo, not a compile-time type.
On Monday, 6 May 2013 at 23:53:51 UTC, Idan Arye wrote:
If the type handlers are your own classes, then you can let
them check it. Have a method in the handlers that check if an
object can be handled by that handler, and use it on each
handler until you find one that fits.
I don't
On Monday, 6 May 2013 at 23:48:11 UTC, Sean Kelly wrote:
How are the messages stored? std.concurrency uses
Variant.convertsTo.
I had looked at Variant.convertsTo but (IIRC) it accepts a type
(not a TypeInfo) and in my design I no longer had the type
avaliable in the place where I would use
18 matches
Mail list logo