设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
楼主: 紫苏
打印 上一主题 下一主题

[胡扯] 蛋疼数学程序帝!散列算法

 关闭 [复制链接]

Lv4.逐梦者

梦石
0
星屑
6645
在线时间
1666 小时
注册时间
2008-10-29
帖子
6710

贵宾

41
发表于 2010-9-18 22:08:57 | 只看该作者
也不知道怎么的.
昨天晚上躺在床上准备睡觉的时候莫名其妙的就想到了这个帖子.
然后就莫名其妙的想到了这个方法.不知道可不可行.
除了 整数 类的对象在 RGSS 里是唯一的外.
符号 类的对象也是唯一的.
起初是用的数组的 pack("ll") 后 to_sym 弄成 符号
然后就改用 Marshal.dump 后再 to_sym

  1. class Point < Array
  2.   def initialize(x, y)
  3.     super(2)
  4.     self[0] = x
  5.     self[1] = y
  6.   end
  7.   def x
  8.     return self[0].nil? ? 0 : self[0]
  9.   end
  10.   def y
  11.     return self[1].nil? ? 0 : self[1]
  12.   end
  13.   def hash
  14.     if @hash.nil?
  15.       @hash = Marshal.dump(self)
  16.       @hash.gsub!("\0"){ "hzhj" }
  17.       @hash = @hash.to_sym
  18.     end
  19.     return @hash
  20.   end
  21. end
  22. h = {}
  23. h[Point.new(1, 1).hash] = 1
  24. h[Point.new(1, 1).hash] = 2
  25. h[Point.new(1, 1).hash] = 3
  26. h[Point.new(1, 1).hash] = 4

  27. h[Point.new(1, 0).hash] = 11
  28. h[Point.new(1, 0).hash] = 12
  29. h[Point.new(0, 1).hash] = 13
  30. h[Point.new(0, 1).hash] = 14

  31. h[Point.new(2, 0).hash] = 15
  32. h[Point.new(2, 0).hash] = 16
  33. h[Point.new(0, 2).hash] = 17
  34. h[Point.new(0, 2).hash] = 18

  35. h[Point.new(0b10001000100010001000, 0b10011001100110011001).hash] = 19
  36. h[Point.new(0b10001000100010001000, 0b10011001100110011001).hash] = 20

  37. h[Point.new(0b10001000100010001000, 0b10011001100110011000).hash] = 21
  38. h[Point.new(0b10001000100010001000, 0b10011001100110011000).hash] = 22

  39. h[Point.new(0b10001000100010001000101010101010,
  40.             0b10011001100110011001100110011001).hash] = 23
  41. h[Point.new(0b10001000100010001000101010101010,
  42.             0b10011001100110011001100110011001).hash] = 24


  43. p h[Point.new(1, 1).hash],Point.new(1, 1).hash,
  44.   h[Point.new(1, 0).hash],Point.new(1, 0).hash,
  45.   h[Point.new(0, 1).hash],Point.new(0, 1).hash,
  46.   h[Point.new(2, 0).hash],Point.new(2, 0).hash,
  47.   h[Point.new(0, 2).hash],Point.new(0, 2).hash,
  48.   h[Point.new(0b10001000100010001000, 0b10011001100110011001).hash],
  49.   Point.new(0b10001000100010001000, 0b10011001100110011001).hash,
  50.   h[Point.new(0b10001000100010001000, 0b10011001100110011000).hash],
  51.   Point.new(0b10001000100010001000, 0b10011001100110011000).hash,
  52.   h[Point.new(0b10001000100010001000101010101010,
  53.             0b10011001100110011001100110011001).hash],
  54.   Point.new(0b10001000100010001000101010101010,
  55.             0b10011001100110011001100110011001).hash

  56. exit
复制代码











你知道得太多了

回复 支持 反对

使用道具 举报

头像被屏蔽

Lv1.梦旅人 (禁止发言)

梦石
0
星屑
49
在线时间
0 小时
注册时间
2010-9-18
帖子
185
42
发表于 2010-9-18 22:13:56 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-6 06:39

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表