0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

haystack?? needle?? なにその命名

Posted at

あらまし

haystackとneedleという命名を見て何のことだろうと思い,調べてみたところ,「find a needle in a haystack」(干し草の中から一本の針を探す)という慣用句に由来することがわかった.

状況

LeetCodeで28. Find the Index of the First Occurrence in a Stringを解いていた時のこと,問題文に,
‘‘‘
Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
‘‘‘
とあった.

解説

「haystack」は「干し草」の意味で,「needle」は「針」.
調べてみると,「find a needle in a haystack」という慣用句があるらしい.意味は,「干し草の中から一本の針を探し出す」であるが,比喩的に,「膨大な数の中から小さなものを見つけ出すくらい難しいこと」とのこと.

ChatGPTに例文を出力してもらったところ

"Trying to find my lost earring in the park is like finding a needle in a haystack."
(公園で失くしたイヤリングを見つけるのは、干し草の山で針を探すようなものだ。)

"Debugging this software bug feels like finding a needle in a haystack."
(このソフトウェアのバグを見つけるのは干し草の山で針を探すような気分だ。)

このように使うらしい.
(「干し草の中の針」として日本語の文脈で使っている人もいるらしい)

要するに,大量のデータの中から特定のデータを見つける時に慣例的に使われている変数らしい.
今後使っていこう.

因みに,PHPではstr_contain()という間数のドキュメントに記載があるらしい.
私はPHPには疎いのでわからなかったが,界隈によっては一般的なのかもしれない.
私の周りでは膾炙していない.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?