• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. Sort alphanumerics

Stats

  • Locked Locked
  • Replies 5
  • Subscribers 144
  • Views 2927
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Sort alphanumerics

piorog
piorog 9 months ago

Is there any simple way to sort alphanumerics using SKILL? I have a combination of pin names ("1, 3, A1, A2... AA1, AA2... AB1...") and I can't find any way to sort them ascending/descending using basing functions.

  • Cancel
Parents
  • p94todorov
    p94todorov 9 months ago

    Hello,

    you can just use the sort function to do that:

    pinNames = list("AB1" "1" "C2" "3" "B" "C" "A1" "D" "A2" "AA1" "AA2")
    pinNames = sort(pinNames 'alphalessp)

    Beware, because the sort function is destructive. If the álphalessp doesn't do what you are looking for you can always use custom lambda as the second argument for sorting, simple example below:

    bBoxes = sort(bBoxes lambda((a b) leftEdge(a) < leftEdge(b) ))

    Regards,
    Petar

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • piorog
    piorog 9 months ago in reply to p94todorov

    Hello,

    unfortunately the sort function does not work ideally. It somehow sort the list but also puts A10 before A2 and so on:

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • mbracht
    mbracht 9 months ago in reply to piorog

    well this requires a little more work, you need to write your own custom comparator function for this. So technically you need to break down every pin name into a leading alphanumeric part and a trailing digital part, best way to do this is a regular expression. The primary sort criteria will be the alphanumeric part. The alphanumeric parts will be compared with alphalessp(). Only if two pins have the same alphanumeric part, the trailing number will be compared with lessp(). What makes things even more tricky is that both the alphanumeric as well as the digital part are optional so there's quite a few corner cases. Below is an example of such a comparator function, It's not the most elegant code in he world but I think it does the job:


    defun myComp (a b)
    (let (a1 a2 b1 b2 (regex (pcreCompile "(\\D+)?(\\d+)?")))
    (if (or (atoi a) (atoi b)) then
    (cond
    ((and (atoi a) (atoi b))
    (lessp (atoi a) (atoi b)))
    ((atoi a)
    t)
    ((atoi b)
    nil))
    else
    (pcreExecute regex a)
    a1 = (pcreSubstitute regex "\\1")
    a2 = (pcreSubstitute regex "\\2")
    (pcreExecute regex b)
    b1 = (pcreSubstitute regex "\\1")
    b2 = (pcreSubstitute regex "\\2")
    (if (a1==b1)
    (lessp (or (atoi a2) 0) (or (atoi b2) 0))
    (alphalessp a1 b1)))))

    pinNames=(sort pinNames 'myComp)

    Max

    • Cancel
    • Vote Up +2 Vote Down
    • Cancel
Reply
  • mbracht
    mbracht 9 months ago in reply to piorog

    well this requires a little more work, you need to write your own custom comparator function for this. So technically you need to break down every pin name into a leading alphanumeric part and a trailing digital part, best way to do this is a regular expression. The primary sort criteria will be the alphanumeric part. The alphanumeric parts will be compared with alphalessp(). Only if two pins have the same alphanumeric part, the trailing number will be compared with lessp(). What makes things even more tricky is that both the alphanumeric as well as the digital part are optional so there's quite a few corner cases. Below is an example of such a comparator function, It's not the most elegant code in he world but I think it does the job:


    defun myComp (a b)
    (let (a1 a2 b1 b2 (regex (pcreCompile "(\\D+)?(\\d+)?")))
    (if (or (atoi a) (atoi b)) then
    (cond
    ((and (atoi a) (atoi b))
    (lessp (atoi a) (atoi b)))
    ((atoi a)
    t)
    ((atoi b)
    nil))
    else
    (pcreExecute regex a)
    a1 = (pcreSubstitute regex "\\1")
    a2 = (pcreSubstitute regex "\\2")
    (pcreExecute regex b)
    b1 = (pcreSubstitute regex "\\1")
    b2 = (pcreSubstitute regex "\\2")
    (if (a1==b1)
    (lessp (or (atoi a2) 0) (or (atoi b2) 0))
    (alphalessp a1 b1)))))

    pinNames=(sort pinNames 'myComp)

    Max

    • Cancel
    • Vote Up +2 Vote Down
    • Cancel
Children
No Data

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.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information