Guest User

Untitled

a guest
Nov 24th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 6.64 KB | None | 0 0
  1.  
  2. proc simpleTreeDiff*[T, L, V](
  3.     source, target: T,
  4.     getLabel: proc(t: T): L,
  5.     getValue: proc(t: T): V,
  6.     valueScore: ScoreCmpProc[V],
  7.     similarityTreshold: int = 60,
  8.     initialMapping: bool = true
  9.   ): auto =
  10.  
  11.   # ^^^^ implementation noise, included for context
  12.  
  13.  
  14.   # vvvv if I have this *order of statements* things work fine
  15.   let
  16.     sourceIndex: TreeIndex[L, V] = makeIndex[T, L, V](
  17.       source, true, getValue, getLabel)
  18.  
  19.   var tmp: Table[NodeId[L, V], NodeId[L, V]]
  20.  
  21.   let
  22.     targetIndex: TreeIndex[L, V] = makeIndex[T, L, V](
  23.       target, false, getValue, getLabel)
  24.  
  25.  
  26.  
  27.   # vvvv but if I move it like this, I get erro belov
  28.   var tmp: Table[NodeId[L, V], NodeId[L, V]]
  29.   let
  30.     sourceIndex: TreeIndex[L, V] = makeIndex[T, L, V](
  31.       source, true, getValue, getLabel)
  32.  
  33.  
  34.   let
  35.     targetIndex: TreeIndex[L, V] = makeIndex[T, L, V](
  36.       target, false, getValue, getLabel)
  37.  
  38.  
  39.  
  40. #[
  41. /mnt/workspace/github/hmisc/tests/tHTreeDistance.nim(36, 24) template/generic instantiation of `simpleTreeDiff` from here
  42. /mnt/workspace/github/hmisc/src/hmisc/algo/htree_distance.nim(958, 54) template/generic instantiation of `makeIndex` from here
  43. /mnt/workspace/github/hmisc/src/hmisc/algo/htree_distance.nim(163, 31) template/generic instantiation of `[]=` from here
  44. /home/test/.choosenim/toolchains/nim-1.4.0/lib/pure/collections/tableimpl.nim(58, 21) template/generic instantiation of `rawGet` from here
  45. /home/test/.choosenim/toolchains/nim-1.4.0/lib/pure/collections/hashcommon.nim(60, 48) Error: type mismatch: got <string, NodeId[system.string, system.string]>
  46. but expected one of:
  47. proc `==`(x, y: bool): bool
  48.   first type mismatch at position: 1
  49.   required type for x: bool
  50.   but expression 't.data[h].key' is of type: string
  51. proc `==`(x, y: char): bool
  52.   first type mismatch at position: 1
  53.   required type for x: char
  54.   but expression 't.data[h].key' is of type: string
  55. proc `==`(x, y: cstring): bool
  56.   first type mismatch at position: 2
  57.   required type for y: cstring
  58.   but expression 'key' is of type: NodeId[system.string, system.string]
  59. proc `==`(x, y: float): bool
  60.   first type mismatch at position: 1
  61.   required type for x: float
  62.   but expression 't.data[h].key' is of type: string
  63. proc `==`(x, y: float32): bool
  64.   first type mismatch at position: 1
  65.   required type for x: float32
  66.   but expression 't.data[h].key' is of type: string
  67. proc `==`(x, y: int): bool
  68.   first type mismatch at position: 1
  69.   required type for x: int
  70.   but expression 't.data[h].key' is of type: string
  71. proc `==`(x, y: int16): bool
  72.   first type mismatch at position: 1
  73.   required type for x: int16
  74.   but expression 't.data[h].key' is of type: string
  75. proc `==`(x, y: int32): bool
  76.   first type mismatch at position: 1
  77.   required type for x: int32
  78.   but expression 't.data[h].key' is of type: string
  79. proc `==`(x, y: int64): bool
  80.   first type mismatch at position: 1
  81.   required type for x: int64
  82.   but expression 't.data[h].key' is of type: string
  83. proc `==`(x, y: int8): bool
  84.   first type mismatch at position: 1
  85.   required type for x: int8
  86.   but expression 't.data[h].key' is of type: string
  87. proc `==`(x, y: pointer): bool
  88.   first type mismatch at position: 1
  89.   required type for x: pointer
  90.   but expression 't.data[h].key' is of type: string
  91. proc `==`(x, y: string): bool
  92.   first type mismatch at position: 2
  93.   required type for y: string
  94.   but expression 'key' is of type: NodeId[system.string, system.string]
  95. proc `==`(x, y: uint): bool
  96.   first type mismatch at position: 1
  97.   required type for x: uint
  98.   but expression 't.data[h].key' is of type: string
  99. proc `==`(x, y: uint16): bool
  100.   first type mismatch at position: 1
  101.   required type for x: uint16
  102.   but expression 't.data[h].key' is of type: string
  103. proc `==`(x, y: uint32): bool
  104.   first type mismatch at position: 1
  105.   required type for x: uint32
  106.   but expression 't.data[h].key' is of type: string
  107. proc `==`(x, y: uint64): bool
  108.   first type mismatch at position: 1
  109.   required type for x: uint64
  110.   but expression 't.data[h].key' is of type: string
  111. proc `==`(x, y: uint8): bool
  112.   first type mismatch at position: 1
  113.   required type for x: uint8
  114.   but expression 't.data[h].key' is of type: string
  115. proc `==`(x1, x2: XmlNode): bool
  116.   first type mismatch at position: 1
  117.   required type for x1: XmlNode
  118.   but expression 't.data[h].key' is of type: string
  119. proc `==`(x: string; y: type(nil) | type(nil)): bool
  120.   first type mismatch at position: 2
  121.   required type for y: typeof(nil) or typeof(nil)
  122.   but expression 'key' is of type: NodeId[system.string, system.string]
  123. proc `==`(x: type(nil) | type(nil); y: string): bool
  124.   first type mismatch at position: 1
  125.   required type for x: typeof(nil) or typeof(nil)
  126.   but expression 't.data[h].key' is of type: string
  127. proc `==`[A, B](tpl: (Option[A], Option[B]); tpl1: (A, B)): bool
  128.   first type mismatch at position: 1
  129.   required type for tpl: (Option[==.A], Option[==.B])
  130.   but expression 't.data[h].key' is of type: string
  131. proc `==`[Enum: enum](x, y: Enum): bool
  132.   first type mismatch at position: 1
  133.   required type for x: Enum: enum
  134.   but expression 't.data[h].key' is of type: string
  135. proc `==`[I, T](x, y: array[I, T]): bool
  136.   first type mismatch at position: 1
  137.   required type for x: array[I, T]
  138.   but expression 't.data[h].key' is of type: string
  139. proc `==`[T: proc](x, y: T): bool
  140.   first type mismatch at position: 1
  141.   required type for x: T: proc
  142.   but expression 't.data[h].key' is of type: string
  143. proc `==`[T: tuple | object](x, y: T): bool
  144.   first type mismatch at position: 2
  145.   required type for y: T: tuple or object
  146.   but expression 'key' is of type: NodeId[system.string, system.string]
  147. proc `==`[T](opt: Option[T]; val: T): bool
  148.   first type mismatch at position: 1
  149.   required type for opt: Option[==.T]
  150.   but expression 't.data[h].key' is of type: string
  151. proc `==`[T](x, y: openArray[T]): bool
  152.   first type mismatch at position: 2
  153.   required type for y: openArray[T]
  154.   but expression 'key' is of type: NodeId[system.string, system.string]
  155. proc `==`[T](x, y: ptr T): bool
  156.   first type mismatch at position: 1
  157.   required type for x: ptr T
  158.   but expression 't.data[h].key' is of type: string
  159. proc `==`[T](x, y: ref T): bool
  160.   first type mismatch at position: 1
  161.   required type for x: ref T
  162.   but expression 't.data[h].key' is of type: string
  163. proc `==`[T](x, y: seq[T]): bool
  164.   first type mismatch at position: 1
  165.   required type for x: seq[T]
  166.   but expression 't.data[h].key' is of type: string
  167. proc `==`[T](x, y: set[T]): bool
  168.   first type mismatch at position: 1
  169.   required type for x: set[T]
  170.   but expression 't.data[h].key' is of type: string
  171.  
  172. expression: t.data[h].key == key
  173.  
  174. real    0m1.295s
  175. user    0m1.223s
  176. sys 0m0.069s
  177.  
  178. ]#
Advertisement
Add Comment
Please, Sign In to add comment