Idea for ECMA/C# Standard - compile time hash for performance
- From: "wxs" <w@xxxxx>
- Date: Wed, 6 Apr 2005 23:02:18 -0400
Many times we have a bunch of enums we have from either different enums or
the same enum that will have various numeric values assigned. Rarely will
there be collisions in numbering between the enums. These enums you might
imagine would be like OrderPrice=27, OrderQuantity=50, OrderSide=62. There
may be a lot of these. So normally what we would have to do is store these
in hash table so hashtable[OrderPrice]=value could be set with the value.
Hashing is very expensive in terms of performance at the level we deal with.
What would be nice is if the C#/C++ compiler would allow me to do something
like this:
Below example is more C++ pseudo code than C# but you get the idea.
Imagine an original enum:
enum OrderInformation {., OrderPrice=27, OrderQuantity=50, OrderSide=62};
Now imagine if at compile time the compiler could do the hash for us like:
enum map LocalOrderInformation { OrderInformation.OrderPrice alias
OrderPrice=0, OrderInformation.OrderQuantity alias OrderQuantity,
OrderInformation.OrderSide alias OrderSide};
So basically this tells the compiler to create me a new enum mapping the old
enumeration to the new mapping to be 0 based or 1 based so that now we can
use a direct array lookup rather than a hashmap.
So now we could do something like:
int OrderInfo[3];
void OrderClass::ProcessOrder(LocalOrderInformation info, int value)
{
OrderInfo[info]=value;
}
So that a caller if they did something like this:
OrderClassInstance.ProcessOrder(OrderInformation.OrderPrice,27);
The compiler would translate the OrderInformatin.OrderPrice enum to our
LocalOrderInformation enum value for that enum to be 0. Now we can do a
direct array entry rather than a hashtable.
I'm sure there are numerous issues here to work out and it is not quite as
simple as the pseudo code above. But if it were and we could get the
compiler to do this mapping for us our runtime code would be much improved.
I'm sure there are technical hurdles and the need for improved syntax, but
what do people think of the idea? I think it would help a lot of stuff I
work on to avoid hashtables. Thoughts, ideas for better syntax, different
variations?
Thanks,
Dave
.
- Follow-Ups:
- Re: Idea for ECMA/C# Standard - compile time hash for performance
- From: Bruce Wood
- Re: Idea for ECMA/C# Standard - compile time hash for performance
- Prev by Date: Complex design-time property for UserControl
- Next by Date: Businness Entities Problem
- Previous by thread: Complex design-time property for UserControl
- Next by thread: Re: Idea for ECMA/C# Standard - compile time hash for performance
- Index(es):
Relevant Pages
|