• Home
  • :
  • Community
  • :
  • Forums
  • :
  • PCB SKILL
  • :
  • Get the key of table entry found by index

PCB SKILL Forums

Get the key of table entry found by index

RasmusDK
RasmusDK 1 day ago

We are performing translation and migration steps for a customer. We have a file containing information about the connectivity before translation and migration. This files tells us the name of nets as well as which Ref and pin number was connected to the net. This information is read into an association table. Similarly, we have found the nets of the translated board, and generated a similar table, containing also the name of nets and their connected Refs and pin numbers. This information is also stored in an association table.

The goal is to verify that the same nets exist, even if they have a different name now, and to verify that there have been no changes to connectivity. for this purpose, I am iterating on the current table in the outer loop, and iterating the legacy information in the inner loop. Due to performance concerns I wish to stop the inner iteration as soon as I have found a match and are thus using while-loops, rather than for/foreach.

My issue is that when I find a matching connectivity, I can't figure out how to get the key (netname) of the table entry. As seen below in the provided sample code, I am accessing the table entries with an index, rather than a key. How do I get the key associated with a particular table entry, found by index?

;Get an association table of all nets in the design, as well as the pins and referendes that are connected to it
netlist = GetBoardNetlist()

;Read the legacy file containing connectivity information.
LegConList = ReadLegacyConnections()

LegNetName = ""
foreach(netname netlist
j = 0
while(LegNetName == "" && j < length(LegConList)
boardConnections = netlist[netname]
legConnections = LegConList[j]
i = 0
while(LegNetName == "" && i < length(legConnections)
; IF the connections match, set LegNetName to the name of the table entry
)
)
)

  • Reply
  • Cancel
  • Cancel
  • B Bruekers
    B Bruekers 1 day ago

    Can you provide an example of the 'netlist' and 'LegConList' tables?

    • Cancel
    • Up 0 Down
    • Reply
    • Cancel
  • RasmusDK
    RasmusDK 1 day ago in reply to B Bruekers

    Example of entries in each table. There are multiple entries in each table - only one is shown here.

    netlist: netlist["N01234"] = ("C1.1" "R2.1" "R3.1" "R4.1" "TP1.1" "V1.1" "V1.2" "V2.3")

    LegConList: LegConList["XYZ56789"] = ("C1.1" "R2.1" "R3.1" "R4.1" "TP1.1" "V1.1" "V1.2" "V2.3")

    I am checking that the contents of each list (("C1.1" "R2.1" "R3.1" "R4.1" "TP1.1" "V1.1" "V1.2" "V2.3")) is the equivalent, and then trying to map the association that N01234 = XYZ56789, which I need further into the code. My issue is that when I find the correct value (the list of references and pins), I have no way of getting the associated key, even though I know the index of the key in the table.

    • Cancel
    • Up 0 Down
    • Reply
    • Cancel
  • B Bruekers
    B Bruekers 1 day ago in reply to RasmusDK

    A thing to be aware of is the order of the netlist points. So the values in netlist["N01234"]  can be in a different order than LegConList["XYZ56789"].  A simple length of list compare is not sufficient.

    So the way i would approach this is to have a nested foreach loop. Once you found a match with equal list lengths you need to check the contents of it. memv() can check if a string is a member of a list of strings.

    Some code to get you starting:

    ;bogus test data:
    netlist         = makeTable("nets" nil)
    LegConList     = makeTable("nets" nil)
    netlist["N01234"] = '("C1.1" "R2.1" "R3.1" "R4.1" "TP1.1" "V1.1" "V1.2" "V2.3")
    netlist["N012345"] = '("C1.1" "R2.1" "R3.1" "R4.1" "TP1.1" "V1.1" "V1.2")
    LegConList["XYZ56789"] = '("C1.1" "R2.1" "R3.1" "R4.1" "TP1.1" "V1.1" "V1.2" "V2.3")
    LegConList["XZ56789"] = '("C1.1" "R2.1" "R3.1" "R4.1" "TP1.1" "V1.1"  "V1.3")

    ;the actual code:
    netNetTabe = makeTable("nets" nil)
    brdNotMatched = nil
    if(length(netlist->?) == length(LegConList->?)
    then
        foreach(brdNet netlist->?
            netContents1 = netlist[brdNet]
            matched = nil
            foreach(legNet  LegConList->?
                netContents2 = LegConList[legNet]
                ;now compare netContents1 and netContents2.
                ;if found then remove legNet from the table so we don't iterate over it anymore.
                ;first compare length. It's the easiets
                when(length(netContents1) == length(netContents2)
                    when(    forall(netItem1 netContents1 memv(netItem1 netContents2))
                        ;we found equal items in netContents1 and netContents2.
                        remove(legNet LegConList) ; now we remove the item from LegConList
                        netNetTabe[brdNet] = legNet ; store current brd vs legacy netnames.
                        matched = t  ;so we know we had a match
                    )
                )
            )
            unless(matched brdNotMatched = cons(brdNet brdNotMatched))
        )
        foreach(brdNet netNetTabe->?
            axlMsgPut("%s : %s = %L" brdNet netNetTabe[brdNet]  netlist[brdNet])
        )
        foreach(legNet LegConList->?
            axlMsgPut("Not matched legacy -> brd: %s" legNet)
        )
        foreach(brdNet brdNotMatched
            axlMsgPut("Not matched brd -> legacy: %s" brdNet)
        )
    else
        axlMsgPut("Netlist length difference.")
    )

    Resulting in:
    N01234 : XYZ56789 = ("C1.1" "R2.1" "R3.1" "R4.1" "TP1.1" "V1.1" "V1.2" "V2.3")
    Not matched legacy -> brd: XZ56789
    Not matched brd -> legacy: N012345

    The netNetTabe table contains the brd nets vs the legacy nets.

    The matched net from LegConList is removed when a match is found. So the resulting LegConList table contains only items which were not matched.

    If this table is empty then all times were matched with the 'netlist'.  However there is an item in 'netlist' which was not matched with the LegConList it is stored in brdNotMatched.

    • Cancel
    • Up 0 Down
    • Reply
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.