• 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. how to declare an array of unknown size

Stats

  • Locked Locked
  • Replies 11
  • Subscribers 143
  • Views 25543
  • 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

how to declare an array of unknown size

Sri Charan B
Sri Charan B over 13 years ago

Hi,

I am trying to implement a code where i came in need of an array which can increase the size of the array during the runtime. I mean the size of the array shall not be declared using the 'declare' command but during the run time if new elements are to be added into that array i will use it or else the array shall be empty.

I need this because i am at a juncture where i cannot expect or fix the size of the array to a particular value so guys please help me.

Thanks in advance for any help,

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 13 years ago

    I'm not 100% certain what you're after. First of all, arrays can be declared on the fly - so you can create arrays with the size based on a variable - if that's what you want, that's easy. For example, this code here provides a way to create multi-dimensional arrays simply:

    /* abMultiDimArray.il
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       Nov 23, 2009 
    Modified   
    By         
    
    Function for creating a multi-dimensional array.
    
    Usage:
    
    data=abMultiDimArray(6 8)
    
    Creates a 6 by 8 array (starting index is from 0). Then you can use:
    
    data[4][5]=23
    data[0][7]=123
    
    You can specify more dimensions by passing more arguments to abMultiDimArray.
    
    ***************************************************
    
    SCCS Info: @(#) abMultiDimArray.il 11/23/09.16:24:27 1.1
    
    */
    
    procedure(abMultiDimArray(@rest dimensions)
        let((arr)
            if(integerp(car(dimensions)) && plusp(car(dimensions)) then
                arr=makeVector(car(dimensions))
                when(cdr(dimensions)
                    for(ind 0 sub1(car(dimensions))
                        arr[ind]=apply('abMultiDimArray cdr(dimensions))
                    )
                ) ; when 
                arr
            else
                error("Dimension %L must be a positive integer\n" car(dimensions))
            ) ; if
        ) ; let
    ) ; procedure

     

    If however you're asking for a way to declare an array of a certain size, and then make it bigger later, then I would question whether you really want an array. You could either use a list for this dynamic data structure, or you could use a hash (association) table. Which you would use depends on how it is going to be accessed. Lists are good if you can traverse them sequentially, but not good if you want to access the data in a random-access fashion (e.g. you want to access the 10th, or the 15th, or the 2453th entry arbitrarily). Hash tables are good if you want to access the data with random access, but no good if you want any kind of order.

    A table could be created using:

    myArr=makeTable('myArray)

    and then you could use:

    myArr[0]=1
    myArr[1]=2

    and you can arbitrarily add indices later - they can be sparse too - so doing myArr[123456789]=3 is perfectly OK and doesn't have to allocate all the space for the intervening indices. The downside is that the keys are not in any order - so doing myArr->? would give you the keys in some arbitrary order - but provided you're treating it like an array, that shouldn't be an issue.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Sri Charan B
    Sri Charan B over 13 years ago

    Hi Andrew,

    I don't want to declare a multi-dimesional array, but i think i can go with your suggestion of using a list. But the issue here is, i don't want to pass the elements into the list while declaring it, but i will add the elements during the runtime.

    Is that possible with the list?

    Regards,

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 13 years ago

    I didn't expect you to want to use a multi-dimensional array - that was simply an example to show that the size of the array does not need to be a constant - it can be declared on the fly.

    Lists can of course be added to dynamically. Rather than trying to teach you the basics of SKILL, I would strongly suggest that you read the SKILL Language User Guide, particularly the Getting Started chapter which talks about SKILL Lists - and indeed the first few chapters. Lists are pretty fundamental in SKILL and if you don't know how to manipulate them, you're going to get stuck quite quickly.

    The document can be found in cdsdoc (if using IC5141) or cdnshelp (if using IC61), or you can just open <ICinstDir>/doc/sklanguser/sklanguser.pdf

    Note that you should be aware that lists are sequential structures, so adding things onto the beginning of a list is a lot more efficient than adding on the end, and if you find yourself using nth() to access list elements it probably means you are doing things the wrong way (as I said, lists are not arrays). There's a chapter in the user guide on optimisation of code too. Think of the manual as being like a book on programming SKILL that you might buy in a bookshop.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Sri Charan B
    Sri Charan B over 13 years ago

     Hi Andrew,

    Thanks for your support and quick responses. I will try with these lists and see whether it works the way i want it to be.

    Regards,

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Sri Charan B
    Sri Charan B over 13 years ago

     Hi Andrew,

    As per your suggestion i am now able to declare all the elements of the list run time.

    I have an issue here, i have a list

    for example myl='(1 2 3 4 5 6 2 3 1 5)

    n now i need to copy only the unique elements ie) the recursive elements are to be copied only once to another list say

    new='(1 2 3 4 5)

    and the order of these elments is not an issue.

    please help me.

    Regards,

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 13 years ago

    Two implementations:

     procedure(CCFunique(lst)
      let((uniq)
        foreach(elem lst
          unless(member(elem uniq)
            uniq=cons(elem uniq)
          )
        )
        uniq
      )
    )


    procedure(CCFunique(lst)
      let(((uniq makeTable('uniq)))
        foreach(elem lst
          uniq[elem]=t
        )
        uniq->?
      )
    )

    The first uses lists directly, whereas the second uses a hash table to collect the duplicates. The first is probably more straightforward to understand, but will be slower for larger lists (well, if the list of unique items is larger) because the member() function will do a repeated sequential search.

    Take your pick!

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Sri Charan B
    Sri Charan B over 13 years ago

     Thank you Andrew for your help.

    Can you please elaborate the second method. The first was easy for me to understand but the second was a little difficult.

    Regards,

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 13 years ago

    The second code uses a hash table (or an "association table" in SKILL parlance) to store the unique members. You can read up more about these in the SKILL Language User Guide, but the important thing to know is that the table is a bit like an array, except that the indices can be anything, not just numbers. So they can be strings, database ids, numbers, lists, whatever you like.

    The code iterates through the list and for each element it uses that element as the "index" (or key) into the hash table - setting the value of that entry in the table to some arbitrary value (I picked t, but it could have been anything). Tables can actually be iterated with foreach loops - so I could do at the end:

    foreach(elem uniq
      printf("Table entry for %L has value %L\n" elem uniq[elem])
    )

    In addition for a table you can retrieve all the indices (keys) using uniq->? or a list of key-value pairs using uniq->?? . So all I do after populating the table is retrieve all the keys that were used - and since if it used the same key more than once in the foreach loop it will set the same entry  in the table, it will return a unique list of keys.

    Association tables use a hashing mechanism to allow them to efficiently store and lookup entries without having to use sequential searching. If you want to find out more, search for "hash table" on wikipedia (although you probably don't need to understand the implementation ideas behind hash tables to be able to use them effectively).

    Hope that helps,

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Sri Charan B
    Sri Charan B over 13 years ago

    Thank You Andrew for spending your time to elaborate me about the code and also about the tables.

    Regards,

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Rameen
    Rameen over 4 years ago in reply to Andrew Beckett
    Hi Andrew,
    Can u guide me why this error occur? If you have any idea about it,It will be so helpful for me.
    I found this error during elaborate
    "Error   : Array size must be greater than zero. [CDFG-607] [elaborate]
            : Invalid array size: 0.
            : The width of an array must evaluate to a positive integer at compile time."
    There is no module name and line no define
    Why this error occur and how we can debug this that we will in which module this error is occurred
    Regards,
    Rameen.
    • Cancel
    • Vote Up 0 Vote Down
    • 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.

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

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