19

I found in legacy code a class which name is BucketService.

Because english is not my native language I was trying to translate that, but it doesn't make sense.

I found few termins like bucket sorting and so on, but I still don't get it. Actually this word is used quite frequently in programming

I would be helpfull for some simple explanation of that word

2
  • 1
    never judge the class by its name. What API does it expose? what state does it contain? how is it used / invoked / instantiated? without knowing that, the only correct answer to question like yours seems to be Mu
    – gnat
    Apr 18, 2012 at 12:40
  • 2
    Particularly with nondescript name like "BucketService" - it sounds like "UtilityManager" or "ThingDoer". With a vague name like that, your only option is to look at the code. Unfortunately, classes with names that vague generally do a little bit of everything (or a lot of everything, if you're unlucky).
    – Tacroy
    Apr 18, 2012 at 15:41

2 Answers 2

37

A bucket in English is a device for holding water.

When used in software, it normally means a data type that groups objects together.

The term is used often when discussing hashing algorithms, where different items that have the same hash code (hash collision) go into the same "bucket". Meaning, the objects are grouped by the hash.

In general, a hashing function may map several different keys to the same index. Therefore, each slot of a hash table is associated with (implicitly or explicitly) a set of records, rather than a single record. For this reason, each slot of a hash table is often called a bucket, and hash values are also called bucket indices.

Informally, I have seen the term used with dictionaries whose value (not key) is a collection of items.


Wikipedia has a page dedicated to the term as used in computing - Bucket (Computing):

In computing, the term bucket can have several meanings. It is used both as a live metaphor, and as a generally accepted technical term in some specialised areas. A bucket is most commonly a type of data buffer or a type of document in which data is divided into regions.

2
  • 7
    +1 you beat me to it! I would like to add that the purpose of the hash algorithm sorting elements into buckets allows for quicker retrieval and sorting of large collections. If I want to search 20 items for a specific item, then the inefficient way would be to search one at a time by ID. A better way would be for a collection to keep items with the same hash into a bucket, so only a few items need to be searched in the bucket rather than the whole list.
    – maple_shaft
    Apr 18, 2012 at 12:08
  • @maple_shaft - Good point about the use of buckets in hashing. I didn't think it was relevant to the question though :)
    – Oded
    Apr 18, 2012 at 12:27
0

Perhaps it's a reference to 'bit bucket'. That's where the bits that get shifted off a byte go on left and right bit shifts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.