{"id":517,"date":"2004-03-16T23:30:00","date_gmt":"2004-03-16T14:30:00","guid":{"rendered":"\/?p=517"},"modified":"2004-03-16T23:30:00","modified_gmt":"2004-03-16T14:30:00","slug":"hash","status":"publish","type":"post","link":"https:\/\/www.hiro345.net\/blogs\/hiro345\/archives\/517.html","title":{"rendered":"Hash"},"content":{"rendered":"<h2>Hash\u30c6\u30fc\u30d6\u30eb\u306b\u3064\u3044\u3066<\/h2>\n<p>\n\u30e9\u30f3\u30c0\u30e0\u30a2\u30af\u30bb\u30b9\u304c\u53ef\u80fd\u306a\u30c7\u30fc\u30bf\u69cb\u9020\u3068\u3057\u3066\u306f\u914d\u5217\u304c\u3088\u304f\u4f7f\u308f\u308c\u308b\u3002\u3068\u3053\u308d\u304c\u3001\u914d\u5217\u3067\u306f\u6dfb\u5b57\u306b\u6570\u5024\u3057\u304b\u6307\u5b9a\u3067\u304d\u306a\u3044\u3002\u3053\u308c\u3092\u89e3\u6c7a\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u6587\u5b57\u5217\u3092\u6307\u5b9a\u3057\u305f\u3089\u6dfb\u5b57\u306b\u5909\u63db\u3057\u3066\u304f\u308c\u308b\u95a2\u6570(\u30cf\u30c3\u30b7\u30e5\u95a2\u6570)\u3092\u4f7f\u3048\u3070\u826f\u3044\u3002Java\u3067\u306f\u3001java.util.Hashtable\u30af\u30e9\u30b9\u3084java.util.HashMap\u30af\u30e9\u30b9\u306e\u5185\u90e8\u3067\u5229\u7528\u3055\u308c\u3066\u3044\u308b\u3002<\/p>\n<p>\n\u3053\u3053\u3067\u306f\u3001\u539f\u7406\u3092\u77e5\u308b\u305f\u3081\u306b\u30cf\u30c3\u30b7\u30e5\u95a2\u6570\u3092\u3082\u3064\u30af\u30e9\u30b9\u3092\u81ea\u4f5c\u3057\u3066\u307f\u3088\u3046\u3002\n<\/p>\n<p><!--more--><\/p>\n<p>\n\u30cf\u30c3\u30b7\u30e5\u95a2\u6570\u306b\u3088\u308a\u8a08\u7b97\u3055\u308c\u305f\u5024\u306f\u8907\u6570\u306e\u30ad\u30fc\u306b\u5bfe\u3057\u3066\u540c\u3058\u306b\u306a\u308b\u5834\u5408\u304c\u3042\u308a\u3001\u3053\u308c\u3092\u885d\u7a81\u3068\u547c\u3076\u3002\u672c\u6765\u306f\u3053\u306e\u5bfe\u7b56\u3092\u304d\u3061\u3093\u3068\u3059\u308b\u3079\u304d\u3060\u304c\u7c21\u5358\u306e\u305f\u3081\u7701\u7565\u3057\u3066\u3044\u308b\u3002\u3061\u306a\u307f\u306b\u885d\u7a81\u306e\u56de\u907f\u65b9\u6cd5\u306e\u3072\u3068\u3064\u3068\u3057\u3066\u306f\u3001\u7d50\u5408\u30ea\u30b9\u30c8\u3092\u5229\u7528\u3059\u308b\u65b9\u6cd5\u304c\u3042\u308b\u306e\u3067\u8208\u5473\u306e\u3042\u308b\u4eba\u306f\u8003\u3048\u3066\u307f\u3066\u3082\u3089\u3044\u305f\u3044\u3002\n<\/p>\n<p>\n\u6587\u5b57\u5217\u304b\u3089\u30cf\u30c3\u30b7\u30e5\u5024\u3092\u751f\u6210\u3057\u3066\u30e9\u30f3\u30c0\u30e0\u30a2\u30af\u30bb\u30b9\u3059\u308b\u305f\u3081\u306b\u3001\u6587\u5b57\u5217\u306e\u6700\u521d\u3068\u771f\u4e2d\u3068\u6700\u5f8c\u306e\u6587\u5b57\u304b\u3089\u30010\u304b\u3089999\u307e\u3067\u306e\u5024\u306b\u5909\u63db\u3059\u308bhash\u30e1\u30bd\u30c3\u30c9\u3092\u7528\u610f\u3057\u3066\u3044\u308b\u3002\u5024(value)\u3092\u683c\u7d0d\u3057\u305f\u308a\u3001\u53d6\u308a\u3060\u3059\u306b\u306f key \u3068\u306a\u308b\u6587\u5b57\u5217\u3092\u30d1\u30e9\u30e1\u30fc\u30bf\u3068\u3057\u3066\u53d7\u3051\u53d6\u308bput\u30e1\u30bd\u30c3\u30c9\u3084get\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3059\u308b\u3002Hash\u30c6\u30fc\u30d6\u30eb\u306e\u30a4\u30e1\u30fc\u30b8\u304c\u3064\u304b\u3081\u305f\u3060\u308d\u3046\u304b\u3002\n<\/p>\n<div class=\"code\">public class Hash {<br \/>\n  private final int MODSIZE = 1000;<br \/>\n  private Object[] values = new Object[MODSIZE];<br \/>\n  public Object get(String key) throws Exception {<br \/>\n    return values[hash(key)];<br \/>\n  }<br \/>\n  public void put(String key, Object value) throws Exception {<br \/>\n    values[hash(key)] = value;<br \/>\n  }<br \/>\n  public int hash(String s) throws Exception {<br \/>\n    int n = s.length();<br \/>\n    if (n < 3) throw new Exception(\"Illegal argument\");\n    return ( s.charAt(0)-'A'+\n            (s.charAt(n\/2-1)-'A')*26+\n            (s.charAt(n-2)-'A')*26*26 ) % MODSIZE;\n  }\n}<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hash\u30c6\u30fc\u30d6\u30eb\u306b\u3064\u3044\u3066 \u30e9\u30f3\u30c0\u30e0\u30a2\u30af\u30bb\u30b9\u304c\u53ef\u80fd\u306a\u30c7\u30fc\u30bf\u69cb\u9020\u3068\u3057\u3066\u306f\u914d\u5217\u304c\u3088\u304f\u4f7f\u308f\u308c\u308b\u3002\u3068\u3053\u308d\u304c\u3001\u914d\u5217\u3067\u306f\u6dfb\u5b57\u306b\u6570\u5024\u3057\u304b\u6307\u5b9a\u3067\u304d\u306a\u3044\u3002\u3053\u308c\u3092\u89e3\u6c7a\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u6587\u5b57\u5217\u3092\u6307\u5b9a\u3057\u305f\u3089\u6dfb\u5b57\u306b\u5909\u63db\u3057\u3066\u304f\u308c\u308b\u95a2\u6570(\u30cf\u30c3\u30b7\u30e5\u95a2\u6570)\u3092\u4f7f &hellip; <a href=\"https:\/\/www.hiro345.net\/blogs\/hiro345\/archives\/517.html\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-517","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/517","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/comments?post=517"}],"version-history":[{"count":0,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/517\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/media?parent=517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/categories?post=517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/tags?post=517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}