Hex Artifact Content
Not logged in

Artifact 01a2602f05b036ac5c8770b88c89bf824f5222d4:


0000: 2f 2f 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  //--------------
0010: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0020: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0030: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
0040: 2f 2f 20 49 44 20 41 73 73 69 67 6e 6d 65 6e 74  // ID Assignment
0050: 0a 2f 2f 0a 2f 2f 20 56 65 72 69 66 69 65 64 20  .//.// Verified 
0060: 62 79 0a 2f 2f 20 20 20 2d 20 41 43 4d 2f 49 43  by.//   - ACM/IC
0070: 50 43 20 54 6f 6b 79 6f 20 32 30 31 30 20 41 0a  PC Tokyo 2010 A.
0080: 2f 2f 20 20 20 2d 20 53 52 4d 20 34 39 31 20 44  //   - SRM 491 D
0090: 69 76 31 20 4c 56 33 0a 2f 2f 2d 2d 2d 2d 2d 2d  iv1 LV3.//------
00a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
00b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
00c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
00d0: 2d 2d 2d 2d 2d 2d 2d 0a 0a 74 65 6d 70 6c 61 74  -------..templat
00e0: 65 3c 74 79 70 65 6e 61 6d 65 20 54 3e 0a 63 6c  e<typename T>.cl
00f0: 61 73 73 20 49 64 47 65 6e 0a 7b 0a 09 6d 61 70  ass IdGen.{..map
0100: 3c 54 2c 20 69 6e 74 3e 20 76 32 69 64 5f 3b 0a  <T, int> v2id_;.
0110: 09 76 65 63 74 6f 72 3c 54 3e 20 20 20 69 64 32  .vector<T>   id2
0120: 76 5f 3b 0a 70 75 62 6c 69 63 3a 0a 09 69 6e 74  v_;.public:..int
0130: 20 76 32 69 64 28 63 6f 6e 73 74 20 54 26 20 76   v2id(const T& v
0140: 29 20 7b 0a 09 09 69 66 28 20 21 76 32 69 64 5f  ) {...if( !v2id_
0150: 2e 63 6f 75 6e 74 28 76 29 20 29 20 7b 20 76 32  .count(v) ) { v2
0160: 69 64 5f 5b 76 5d 20 3d 20 73 69 7a 65 28 29 3b  id_[v] = size();
0170: 20 69 64 32 76 5f 2e 70 75 73 68 5f 62 61 63 6b   id2v_.push_back
0180: 28 76 29 3b 20 7d 0a 09 09 72 65 74 75 72 6e 20  (v); }...return 
0190: 76 32 69 64 5f 5b 76 5d 3b 0a 09 7d 0a 09 63 6f  v2id_[v];..}..co
01a0: 6e 73 74 20 54 26 20 69 64 32 76 28 69 6e 74 20  nst T& id2v(int 
01b0: 69 29 20 63 6f 6e 73 74 20 7b 20 72 65 74 75 72  i) const { retur
01c0: 6e 20 69 64 32 76 5f 5b 69 5d 3b 20 7d 0a 09 69  n id2v_[i]; }..i
01d0: 6e 74 20 73 69 7a 65 28 29 20 63 6f 6e 73 74 20  nt size() const 
01e0: 7b 20 72 65 74 75 72 6e 20 69 64 32 76 5f 2e 73  { return id2v_.s
01f0: 69 7a 65 28 29 3b 20 7d 0a 7d 3b 0a              ize(); }.};.