less_retarded_wiki/collision.md
2022-11-01 21:41:16 +01:00

1.3 KiB

Collision

Collision, sometimes also conflict, happens when two or more things want to occupy the same spot. This situation usually needs to be addressed somehow; then we talk about collision resolution. In programming there are different types of collisions, for example:

  • hash collision: When two items produce the same hash, they will map to the same index in a hash table. Typical solution is to have a list at each table index so that multiple items can fit there.
  • collision of bodies in a physics engine: See collision_detection. These collision are resolved by separating the bodies and updating their velocities so that they "bounce off" as in real life.
  • request collision: General situation in which multiple clients request access to something that can be used only by one client at a time, e.g. a communication bus. Resolution is usually done by some kind of arbiter who decides, by whatever algorithm, who to grant the access to.
  • name collision: When e.g. the same identifier is used in two separate libraries that are included at the same time, the compiler doesn't know which one is intended. This is addressed by namespaces.