Skip to content

Sentinel value

종료 조건 등으로 사용하는 특별한 의미의 값.

컴퓨터 프로그래밍에서 센티널 값은 일반적으로 루프 또는 재귀 알고리즘에서 종료 조건으로 존재를 사용하는 알고리즘의 맥락에서 특별한 값입니다.

센티넬 값은 대역 외 데이터가 제공되지 않을 때 데이터의 끝을 감지할 수 있는 대역 내 데이터의 한 형태입니다.

In computer programming, a sentinel value (also referred to as a flag value, trip value, rogue value, signal value, or dummy data) is a special value in the context of an algorithm which uses its presence as a condition of termination, typically in a loop or recursive algorithm.

The sentinel value is a form of in-band data that makes it possible to detect the end of the data when no out-of-band data (such as an explicit size indication) is provided. The value should be selected in such a way that it is guaranteed to be distinct from all legal data values since otherwise, the presence of such values would prematurely signal the end of the data (the semipredicate problem). A sentinel value is sometimes known as an "Elephant in Cairo", due to a joke where this is used as a physical sentinel. In safe languages, most sentinel values could be replaced with option types, which enforce explicit handling of the exceptional case.

Examples

Some examples of common sentinel values and their uses:

  • Null character for indicating the end of a null-terminated string.
  • Null pointer for indicating the end of a linked list or a tree.
  • A set most significant bit in a stream of equally spaced data values, for example, a set 8th bit in a stream of 7-bit ASCII characters stored in 8-bit bytes indicating a special property (like inverse video, boldface or italics) or the end of the stream.
  • A negative integer for indicating the end of a sequence of non-negative integers. (e.g. NOT_FOUND_INDEX = -1)

See also

Favorite site