• 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. Fastest way to merge two lists without duplicates

Stats

  • Locked Locked
  • Replies 9
  • Subscribers 144
  • Views 19072
  • 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

Fastest way to merge two lists without duplicates

zmleitao
zmleitao over 11 years ago

When developing SKILL scripts I find the need to join or merge two lists, while avoiding duplicate items.

E.g.:

list1 = '(a b c) 

list2 = '(a d c )

merge_func(list1, list2) -> '(a b c d )

Is there a fast/native way to do it in SKILL that is not the obvious iterative solution?

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 11 years ago

    I did some profiling with a list of 1 million integers (passed twice to the function). Here's the findings (on my laptop, so not the absolutely fastest machine around):

    1. My CCFmergedLists implementation: 1.85s
    2. artUnique solution: gave up after 170s (so very slow)
    3. ciUniqueMembers solution - only works with strings and has to do some list creation to get into the right format. With a list of a million strings passed twice via append, took 9.6s (uses sortcar inside)
    4. Tom's unordered approach which uses a table: 0.84s
    5. An improvement upon this which uses a foreach loop rather than using append:
      procedure(CCFmergedLists3(@rest lists)
      let((myTable)
          myTable = makeTable("temp" nil)
          foreach(lst lists
          foreach(element lst myTable[element] = t)
          )
          myTable->?
      ))

      This took 0.66s
    6. The optimized for small integers (I increased the array size to over 1million to profile it with reasonable data): 0.95s
    7. Tom's refinement of my ordered solution which uses a table which returns t by default (won't work directly as using uniq[elem]=nil as the second arg to && will always return nil. So I used prog1 instead:
        procedure(CCFmergedLists4(@rest lists)
        let(((uniq makeTable('uniq t)))
          foreach(mapcan lst lists
              setof(elem lst
                prog1(uniq[elem] uniq[elem]=nil)
              )
          )
        )
      )

      This took 1.45s

    So the winners are:

    Ordered: 7 in the above list (CCFmergedLists4) - 1.45s
    Unordered: 5 in the above list (CCFmergedLists3) - 0.66s

    For two million entry lists, which is probably far bigger than you'd ever use this for, these should be good enough (as was my original solution - the others are not massively faster). Maybe small optimizations here and there could be made, Also your mileage may vary with different input data for profiling...

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 11 years ago

    I did some profiling with a list of 1 million integers (passed twice to the function). Here's the findings (on my laptop, so not the absolutely fastest machine around):

    1. My CCFmergedLists implementation: 1.85s
    2. artUnique solution: gave up after 170s (so very slow)
    3. ciUniqueMembers solution - only works with strings and has to do some list creation to get into the right format. With a list of a million strings passed twice via append, took 9.6s (uses sortcar inside)
    4. Tom's unordered approach which uses a table: 0.84s
    5. An improvement upon this which uses a foreach loop rather than using append:
      procedure(CCFmergedLists3(@rest lists)
      let((myTable)
          myTable = makeTable("temp" nil)
          foreach(lst lists
          foreach(element lst myTable[element] = t)
          )
          myTable->?
      ))

      This took 0.66s
    6. The optimized for small integers (I increased the array size to over 1million to profile it with reasonable data): 0.95s
    7. Tom's refinement of my ordered solution which uses a table which returns t by default (won't work directly as using uniq[elem]=nil as the second arg to && will always return nil. So I used prog1 instead:
        procedure(CCFmergedLists4(@rest lists)
        let(((uniq makeTable('uniq t)))
          foreach(mapcan lst lists
              setof(elem lst
                prog1(uniq[elem] uniq[elem]=nil)
              )
          )
        )
      )

      This took 1.45s

    So the winners are:

    Ordered: 7 in the above list (CCFmergedLists4) - 1.45s
    Unordered: 5 in the above list (CCFmergedLists3) - 0.66s

    For two million entry lists, which is probably far bigger than you'd ever use this for, these should be good enough (as was my original solution - the others are not massively faster). Maybe small optimizations here and there could be made, Also your mileage may vary with different input data for profiling...

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 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