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

  • Home
  • SEARCH
  • 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 6594171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:46:35+00:00 2026-05-25T17:46:35+00:00

There’s this code from here ub4 additive(char *key, ub4 len, ub4 prime) { ub4

  • 0

There’s this code from here

ub4 additive(char *key, ub4 len, ub4 prime)
{
  ub4 hash, i;
  for (hash=len, i=0; i<len; ++i) 
    hash += key[i];
  return (hash % prime);
}

They say this takes 5n+3 instructions. How did they calculate it? How should i calculate it?

  • 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-25T17:46:36+00:00Added an answer on May 25, 2026 at 5:46 pm

    To make this calculation You need some base primitive system. For instance in The art of Computer programming, Knuth uses the MIX computer to do these kind of calculations. Different base computers might have different instructions, and different outcomes to this kind of calculation. In your particular example a common way to set it up would be:

    • hash <- len (1 op)
    • i <- 0 (1 op)
    • i < len, i++ (2*n ops)
    • key[i] lookup (n ops)
    • hash + key[i] (n ops)
    • hash <- hash + key (n ops)
    • hash % prime (1 op)

    and this would sum up as 5n + 3.

    Variations might be along the lines of:

    • declaring/creating the two hash and i, might be time consuming. A normal cpu might not need to do extra work because of the declarations, think register/stack storage.
    • the hash += hash + key[i] might be counted as one operation on the base system, and so on.

    Edit: Note that these kind of calculations are mostly useful as thought experiments on hypothetical hardware. A real life processor would quite likely not behave exactly as these calculations other than in very rare cases.

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

Sidebar

Related Questions

There was some code like this: // Convenience to make things more legible in
There is previous little on the google on this subject other than people asking
There are numerous libraries providing Linq capabilities to C# code interacting with a MySql
For some reason, after submitting a string like this Jack’s Spindle from a text
There is one table T ( id integer, primary key ( id). I want
There is something I am missing. Say I have the following code: private Bitmap
There is a file as data.html. How to display the contents of this file
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
There are many tutorials that talk about deleting index.php from the url. But I
There must be a simple solution to this, but after 4 hours of browsing

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.