Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 620867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:48:42+00:00 2026-05-13T18:48:42+00:00

I have a hashing method whose operations depend on input to the function. Profiling

  • 0

I have a hashing method whose operations depend on input to the function. Profiling the program has shown that too much time is spent evaluating this hash method. I want to try changing it into an expression tree, so the inner loop checks can be done once. Hopefully it will be faster, but I’ll learn about expression trees either way.

Here is a simplified version of the function (I undid some obvious optimizations for the example, and took out any input validation):

Private Function Checksum(ByVal inputValues As IEnumerable(Of UInt32),
                          ByVal declarations As IEnumerable(Of String),
                          ByVal statements As IEnumerable(Of String)) As UInt32
    Dim variables = New Dictionary(Of Char, UInt32)

    For Each declaration In declarations
        'parse declaration (eg. "X=52")'
        variables(declaration(0)) = UInt32.Parse(declaration.Substring(2))
    Next declaration

    For Each value In inputValues
        '"I"nput'
        variables("I"c) = value

        For Each statement In statements
            'parse statement (eg. "X=Y+Z")'
            Dim varResult = statement(0)
            Dim valueLeft = variables(statement(2))
            Dim operand = statement(3)
            Dim valueRight = variables(statement(4))

            'execute statement'
            Dim valueResult As UInt32
            Select Case operand
                Case "+"c : valueResult = valueLeft + valueRight
                Case "-"c : valueResult = valueLeft - valueRight
                Case "*"c : valueResult = valueLeft * valueRight
                Case "&"c : valueResult = valueLeft And valueRight
                Case "|"c : valueResult = valueLeft Or valueRight
                Case "^"c : valueResult = valueLeft Xor valueRight
            End Select
            variables(varResult) = valueResult
        Next statement
    Next value

    '"O"utput'
    Return variables("O"c)
End Function

I want to create a function which takes the declarations and statements and outputs a specialized expression tree representing a function which takes an IEnumerable of UInt32 and returns a UInt32.


Follow-Up:

I succeeded, and the speed-up was ridiculous (an order of magnitude). The main things I had to learn where:

  • Use Expression.Lambda and Expression.Compile to get a delegate you can actually use.
  • The Expression.Block factory method has a ‘variables’ parameter you (essentially) use to declare locals. Similarly, Expression.lambda has ‘parameters’.
  • If you call Expression.Parameter twice, you’re dealing with two different variables (even if their name is the same)! Store the result for later usage. Same for labels, etc.
  • The result of a BlockExpression is the last expression in the block.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:48:42+00:00Added an answer on May 13, 2026 at 6:48 pm

    There was a documentation update with VS 2010 RC. I have added some examples on new ET API here: http://msdn.microsoft.com/en-us/library/bb397951(VS.100).aspx
    It shows how to create local variables and how to execute expression trees. Examples are in both VB and C#.

    But honestly, I still don’t understand what you are trying to do. Why do your declarations and statements come in as strings? And this OpToExp function is also a mystery to me. How did you manage to get operands as expressions, but the operator (which you call “operand” for some reason) as char?
    If you provide more info on what you are trying to do and the overall design of your system, I might help you better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a hashing method in C# that looks like: MD5CryptoServiceProvider md5 = new
I have a sparsely populated vector that I populated via hashing, so elements are
I have two salts, each user has a unique salt that is stored with
I have a Dictionary<string,int> that has the potential to contain upwards of 10+ million
I have a Java program that stores a lot of mappings from Strings to
I have a user table in my mysql database that has a password column.
I have often heard people talking about hashing and hash maps and hash tables.
Predis claim to have Client-side sharding (support for consistent hashing of keys). http://github.com/nrk/predis I
I am re-hashing this question because I have looked at over 50 threads in
I know very little about encryption/hashing. I have to hash an encryption key. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.