You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
4.2 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. package merkle
  2. import (
  3. "encoding/binary"
  4. )
  5. type Int8 int8
  6. type UInt8 uint8
  7. type Int16 int16
  8. type UInt16 uint16
  9. type Int32 int32
  10. type UInt32 uint32
  11. type Int64 int64
  12. type UInt64 uint64
  13. type Int int
  14. type UInt uint
  15. func (self Int8) Equals(other Key) bool {
  16. if o, ok := other.(Int8); ok {
  17. return self == o
  18. } else {
  19. return false
  20. }
  21. }
  22. func (self Int8) Less(other Key) bool {
  23. if o, ok := other.(Int8); ok {
  24. return self < o
  25. } else {
  26. return false
  27. }
  28. }
  29. func (self Int8) Bytes() []byte {
  30. return []byte{byte(self)}
  31. }
  32. func (self UInt8) Equals(other Key) bool {
  33. if o, ok := other.(UInt8); ok {
  34. return self == o
  35. } else {
  36. return false
  37. }
  38. }
  39. func (self UInt8) Less(other Key) bool {
  40. if o, ok := other.(UInt8); ok {
  41. return self < o
  42. } else {
  43. return false
  44. }
  45. }
  46. func (self UInt8) Bytes() []byte {
  47. return []byte{byte(self)}
  48. }
  49. func (self Int16) Equals(other Key) bool {
  50. if o, ok := other.(Int16); ok {
  51. return self == o
  52. } else {
  53. return false
  54. }
  55. }
  56. func (self Int16) Less(other Key) bool {
  57. if o, ok := other.(Int16); ok {
  58. return self < o
  59. } else {
  60. return false
  61. }
  62. }
  63. func (self Int16) Bytes() []byte {
  64. b := [2]byte{}
  65. binary.LittleEndian.PutUint16(b[:], uint16(self))
  66. return b[:]
  67. }
  68. func (self UInt16) Equals(other Key) bool {
  69. if o, ok := other.(UInt16); ok {
  70. return self == o
  71. } else {
  72. return false
  73. }
  74. }
  75. func (self UInt16) Less(other Key) bool {
  76. if o, ok := other.(UInt16); ok {
  77. return self < o
  78. } else {
  79. return false
  80. }
  81. }
  82. func (self UInt16) Bytes() []byte {
  83. b := [2]byte{}
  84. binary.LittleEndian.PutUint16(b[:], uint16(self))
  85. return b[:]
  86. }
  87. func (self Int32) Equals(other Key) bool {
  88. if o, ok := other.(Int32); ok {
  89. return self == o
  90. } else {
  91. return false
  92. }
  93. }
  94. func (self Int32) Less(other Key) bool {
  95. if o, ok := other.(Int32); ok {
  96. return self < o
  97. } else {
  98. return false
  99. }
  100. }
  101. func (self Int32) Bytes() []byte {
  102. b := [4]byte{}
  103. binary.LittleEndian.PutUint32(b[:], uint32(self))
  104. return b[:]
  105. }
  106. func (self UInt32) Equals(other Key) bool {
  107. if o, ok := other.(UInt32); ok {
  108. return self == o
  109. } else {
  110. return false
  111. }
  112. }
  113. func (self UInt32) Less(other Key) bool {
  114. if o, ok := other.(UInt32); ok {
  115. return self < o
  116. } else {
  117. return false
  118. }
  119. }
  120. func (self UInt32) Bytes() []byte {
  121. b := [4]byte{}
  122. binary.LittleEndian.PutUint32(b[:], uint32(self))
  123. return b[:]
  124. }
  125. func (self Int64) Equals(other Key) bool {
  126. if o, ok := other.(Int64); ok {
  127. return self == o
  128. } else {
  129. return false
  130. }
  131. }
  132. func (self Int64) Less(other Key) bool {
  133. if o, ok := other.(Int64); ok {
  134. return self < o
  135. } else {
  136. return false
  137. }
  138. }
  139. func (self Int64) Bytes() []byte {
  140. b := [8]byte{}
  141. binary.LittleEndian.PutUint64(b[:], uint64(self))
  142. return b[:]
  143. }
  144. func (self UInt64) Equals(other Key) bool {
  145. if o, ok := other.(UInt64); ok {
  146. return self == o
  147. } else {
  148. return false
  149. }
  150. }
  151. func (self UInt64) Less(other Key) bool {
  152. if o, ok := other.(UInt64); ok {
  153. return self < o
  154. } else {
  155. return false
  156. }
  157. }
  158. func (self UInt64) Bytes() []byte {
  159. b := [8]byte{}
  160. binary.LittleEndian.PutUint64(b[:], uint64(self))
  161. return b[:]
  162. }
  163. func (self Int) Equals(other Key) bool {
  164. if o, ok := other.(Int); ok {
  165. return self == o
  166. } else {
  167. return false
  168. }
  169. }
  170. func (self Int) Less(other Key) bool {
  171. if o, ok := other.(Int); ok {
  172. return self < o
  173. } else {
  174. return false
  175. }
  176. }
  177. func (self Int) Bytes() []byte {
  178. b := [8]byte{}
  179. binary.LittleEndian.PutUint64(b[:], uint64(self))
  180. return b[:]
  181. }
  182. func (self UInt) Equals(other Key) bool {
  183. if o, ok := other.(UInt); ok {
  184. return self == o
  185. } else {
  186. return false
  187. }
  188. }
  189. func (self UInt) Less(other Key) bool {
  190. if o, ok := other.(UInt); ok {
  191. return self < o
  192. } else {
  193. return false
  194. }
  195. }
  196. func (self UInt) Bytes() []byte {
  197. b := [8]byte{}
  198. binary.LittleEndian.PutUint64(b[:], uint64(self))
  199. return b[:]
  200. }