tmget.nim 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. discard """
  2. matrix: "--mm:refc; --mm:orc"
  3. output: '''Can't access 6
  4. 10
  5. 11
  6. 2
  7. Can't access 6
  8. 10
  9. 11
  10. 2
  11. Can't access 6
  12. 10
  13. 11
  14. 2
  15. Can't access 6
  16. 10
  17. 11
  18. 2
  19. 0
  20. 10
  21. 11
  22. 0
  23. 10
  24. 11
  25. Can't access 6
  26. 5
  27. Can't access 6
  28. 10
  29. 11
  30. Can't access 6
  31. 10
  32. 11'''
  33. """
  34. import tables
  35. block:
  36. var x = initTable[int, int]()
  37. x[5] = 10
  38. try:
  39. echo x[6]
  40. except KeyError:
  41. echo "Can't access 6"
  42. echo x[5]
  43. x[5] += 1
  44. var c = x[5]
  45. echo c
  46. x.mgetOrPut(7).inc
  47. x.mgetOrPut(7).inc
  48. echo x[7]
  49. block:
  50. var x = newTable[int, int]()
  51. x[5] = 10
  52. try:
  53. echo x[6]
  54. except KeyError:
  55. echo "Can't access 6"
  56. echo x[5]
  57. x[5] += 1
  58. var c = x[5]
  59. echo c
  60. x.mgetOrPut(7).inc
  61. x.mgetOrPut(7).inc
  62. echo x[7]
  63. block:
  64. var x = initOrderedTable[int, int]()
  65. x[5] = 10
  66. try:
  67. echo x[6]
  68. except KeyError:
  69. echo "Can't access 6"
  70. echo x[5]
  71. x[5] += 1
  72. var c = x[5]
  73. echo c
  74. x.mgetOrPut(7).inc
  75. x.mgetOrPut(7).inc
  76. echo x[7]
  77. block:
  78. var x = newOrderedTable[int, int]()
  79. x[5] = 10
  80. try:
  81. echo x[6]
  82. except KeyError:
  83. echo "Can't access 6"
  84. echo x[5]
  85. x[5] += 1
  86. var c = x[5]
  87. echo c
  88. x.mgetOrPut(7).inc
  89. x.mgetOrPut(7).inc
  90. echo x[7]
  91. block:
  92. var x = initCountTable[int]()
  93. x[5] = 10
  94. try:
  95. echo x[6]
  96. except KeyError:
  97. echo "Can't access 6"
  98. echo x[5]
  99. x.inc 5, 1
  100. var c = x[5]
  101. echo c
  102. block:
  103. var x = newCountTable[int]()
  104. x[5] = 10
  105. try:
  106. echo x[6]
  107. except KeyError:
  108. echo "Can't access 6"
  109. echo x[5]
  110. x.inc 5, 1
  111. var c = x[5]
  112. echo c
  113. import sets
  114. block:
  115. var x = initHashSet[int]()
  116. x.incl 5
  117. try:
  118. echo x[6]
  119. except KeyError:
  120. echo "Can't access 6"
  121. echo x[5]
  122. import critbits
  123. block:
  124. var x: CritBitTree[int]
  125. x["5"] = 10
  126. try:
  127. echo x["6"]
  128. except KeyError:
  129. echo "Can't access 6"
  130. echo x["5"]
  131. x["5"] += 1
  132. var c = x["5"]
  133. echo c
  134. import strtabs
  135. block:
  136. var x = newStringTable()
  137. x["5"] = "10"
  138. try:
  139. echo x["6"]
  140. except KeyError:
  141. echo "Can't access 6"
  142. echo x["5"]
  143. x["5"][1] = '1'
  144. var c = x["5"]
  145. echo c