Monday, October 30, 2017

How to Remove Duplicates From a Collection ("Uniquify" a Collection)

How to Remove Duplicates From a Collection ("Uniquify" a Collection)
I created a collection containing duplicate members. How can I remove the duplicates so that all members of the collection are unique ("uniquify" the collection)? 
Answer:
A collection is a group of objects which have certain attributes applied on them. Collections have an internal representation and cannot be accessed directly using Tcl list commands. For example, you can use the lsort -ucommand to uniquify objects in a list. This command does not work on a collection.
To uniquify a collection, use: 
add_to_collection -uniquify collection collection
In the following example, my_lc is a collection of lib_cells used in the design.
prompt> set my_lc
{"lib/NAND2X1_LVT","lib/NAND2X1_LVT","lib/NAND2X1_LVT","lib/NAND2X1_LVT"}

prompt> sizeof_collection $my_lc
4

prompt> set t1 [add_to_collection -unique $my_lc $my_lc]
{"lib/NAND2X1_LVT"}

prompt> sizeof_collection $t1
1

Below is one more example. There are points on a timing path. For multiple timing paths, some portion of the path may be common. So the points can be repeated in the collection. The following script uniquifies such collection of points: 

prompt> set path [get_timing_paths -through U16 -max_paths 2]
prompt> set point [get_attribute $path points]
prompt> foreach_in_collection p $point {
  set t1 [add_to_collection $t1 [get_attribute $p object]]
  }
prompt> set t [add_to_collection -unique $t1 $t1]
prompt> sizeof_collection $t1
48
prompt> sizeof_collection $t
28

No comments:

Post a Comment