123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- discard """
- output: '''Can't access 6
- 10
- 11
- Can't access 6
- 10
- 11
- Can't access 6
- 10
- 11
- Can't access 6
- 10
- 11
- 0
- 10
- 11
- 0
- 10
- 11
- Can't access 6
- 5
- Can't access 6
- 10
- 11
- Can't access 6
- 10
- 11'''
- """
- import tables
- block:
- var x = initTable[int, int]()
- x[5] = 10
- try:
- echo x[6]
- except KeyError:
- echo "Can't access 6"
- echo x[5]
- x[5] += 1
- var c = x[5]
- echo c
- block:
- var x = newTable[int, int]()
- x[5] = 10
- try:
- echo x[6]
- except KeyError:
- echo "Can't access 6"
- echo x[5]
- x[5] += 1
- var c = x[5]
- echo c
- block:
- var x = initOrderedTable[int, int]()
- x[5] = 10
- try:
- echo x[6]
- except KeyError:
- echo "Can't access 6"
- echo x[5]
- x[5] += 1
- var c = x[5]
- echo c
- block:
- var x = newOrderedTable[int, int]()
- x[5] = 10
- try:
- echo x[6]
- except KeyError:
- echo "Can't access 6"
- echo x[5]
- x[5] += 1
- var c = x[5]
- echo c
- block:
- var x = initCountTable[int]()
- x[5] = 10
- try:
- echo x[6]
- except KeyError:
- echo "Can't access 6"
- echo x[5]
- x.inc 5, 1
- var c = x[5]
- echo c
- block:
- var x = newCountTable[int]()
- x[5] = 10
- try:
- echo x[6]
- except KeyError:
- echo "Can't access 6"
- echo x[5]
- x.inc 5, 1
- var c = x[5]
- echo c
- import sets
- block:
- var x = initHashSet[int]()
- x.incl 5
- try:
- echo x[6]
- except KeyError:
- echo "Can't access 6"
- echo x[5]
- import critbits
- block:
- var x: CritBitTree[int]
- x["5"] = 10
- try:
- echo x["6"]
- except KeyError:
- echo "Can't access 6"
- echo x["5"]
- x["5"] += 1
- var c = x["5"]
- echo c
- import strtabs
- block:
- var x = newStringTable()
- x["5"] = "10"
- try:
- echo x["6"]
- except KeyError:
- echo "Can't access 6"
- echo x["5"]
- x["5"][1] = '1'
- var c = x["5"]
- echo c
|