Determining number of elements in a bitset?

Neither size() or length() returns the number of bits in the set, so how do I iterate over a bitset?
Bitset bs = new Bitset(10);
bs.set(3,true);
bs.size(); // returns 64 -- who cares about the memory used? Does the JVM even really know?
bs.length(); // returns 4
int i=0;
for(; i<10; i++)
etc...
Is there a method I'm overlooking to return the number of elements in the bitset?
Thx, Chris

Such info is not stored in the bitset object, as you can see reading the source code of java.util.BitSet.
As you can read in the source code, the better you can go is getting the 'logical length' with the method 'length'.
See that 'nbits' is not stored anywhere.
    public BitSet(int nbits) {
     // nbits can't be negative; size 0 is OK
     if (nbits < 0)
         throw new NegativeArraySizeException("nbits < 0: " + nbits);
     bits = new long[(unitIndex(nbits-1) + 1)];
    }

Similar Messages

  • Determining the number of elements defined in an enum

    Hello,
    I have an enum and I want to determine the number of elements (constants) defined in this enum by source code. I know I can use reflection but I just want to know if there's an easier way.
    Thank you very much.

    Hey JavaWisdom,
    You can use the ordinal method. I made a simple example to demonstrate.
    public class NumberOfEnums {
         public static enum Enumeration {
              item1, item2, item3, item4
         public void count() {
              Enumeration[] values = Enumeration.values();
              int numElems = 0;
              for (Enumeration type : values) {
                   if (type.ordinal() > numElems) {
                        numElems = type.ordinal();
              // Correct 0 indexed numbering
              numElems += 1;
              System.out.println("numElems : " + numElems);
         public static void main(String args[]) {
              NumberOfEnums noe = new NumberOfEnums();
              noe.count();
    }Cheers,
    Cypher

  • Automatic determination of WBS element in MIGO

    Dear Friends,
    I have a requirement as below:
    When we do reservation for a particular WBS element and do goods issue for a different WBS element, system is not giving any error message.
    We want to configure automatic determination of WBS element in MIGO_GI from Reservation and the WBS field should be disabled for editing while doing Goods Issue. Please suggest on the required configurations.
    Regards,
    Deepa

    I'm totally agree with Pete.
    This info can accelerate search and development
    IQSM0007 Customer exit for goods movements
    This customer exit is used to transfer the document data for a goods movement into serial number management. This involves:
    The complete goods document (transfer table S7_TAB_MSEG, structure MSEG),
    The purchase order history (transfer table S7_TAB_EKBE, structure EKBE).
    The customer exit is called as soon as the document is saved. This means that at this moment in time the document data can be placed in the global memory of function group XQSM, where it is then available when the serial numbers in the document are saved immediately afterwards.
    Access to the document data (placed in the global memory of IE01) is performed in customer exit EXIT_SAPLIE01_005, which can be activated using customer exit IQSM0005.
    Certain document data can now be copied into the master data of the serial numbers.
    Example
    You want to copy the goods recipient from the material document and the value from the purchase order history into the serial number.
    Goods movement
    You activate the customer exit EXIT_SAPLIE01_007 so that you can prepare the required information from the goods document and the purchase order history. You can read additional data (for example, from the purchase order) where necessary.
    Posting
    You activate the customer exit EXIT_SAPLIE01_005. The data prepared with user exit EXIT_SAPLIE01_007 is available here (for example, goods recipient or purchase order value). This data can be copied into the master data of the serial numbers.

  • Number of elements  to  be defined at  logical level

    In the Business Model and Mapping layer, dimension >Logical Level >> number of elements at this logical level
    I have come across two different version of how to deal with this
    First version - From the OBE and the admin server guide it says "The number does
    not have to be exact, but ratios of numbers from one logical level to another should be accurate".
    Second Version - a question from asked about what defines the number at the level as best practices
    To set the number of elements at each level of a dimension, which number would you use?
    A. the number of columns in a logical table
    B. the number of levels in a dimension
    C. the number of dimensions in a business model
    D. The number of tables in a physical model
    E. the number of distinct rows in physical column
    Question is
    what is the rule to set the number of elements at this level?
    If its been set depending upon the rows in the table . what will happen if the rows gets added every hour ??
    Edited by: ZSAM on Jun 8, 2011 7:06 AM
    Edited by: ZSAM on Jun 8, 2011 8:22 AM

    The ratio between the levels is what is important I believe. BI Server will use this information to determine which aggregate source to use. You should use the number of distinct rows as the value.
    You can also right click the hieracny and use "Estimate Levels" to auto-populate the numbers for you.
    Paul

  • Number of elements in an array

    Hi,
    I have been trying looking for a simple function to get number of elements is an array. Have gone though older posts but could not find answer to it.
    The function should work for following examples:
    char* name = "nInstruments"
    float state[] = {1.0, 2.0}
    I tried sizeof but it returns size of "type" in bytes. For example in example 2, it will just return 4.
    Does someone know a way to do it?
    Ciao
    RB
    Solved!
    Go to Solution.

    RB,
    In C, if an array is declared on the heap, as opposed to on the stack as in your example above, the sizeof operator only returns the length of the pointer that holds the array which, in a 32-bit program, is always 4 bytes. This is because the compiler has no way of knowing how many elements that array actually holds. The length of a C array is a fairly fluid concept. The real size of the array is usually determined by some memory manager somewhere (usually, malloc), but it's not something that the language itself has anything to say about.
    When you declare the entire array as a local variable, however, the compiler must create room for the full array on the stack, and therefore it is able to return the true size of the array via the sizeof operator. (The same is true if it's a global variable, even if it's not on the stack, in that case)
    For this reason, using the sizeof(array) / sizeof(array[0]) trick is iffy. It might work, or it might not work, depending on how the array is declared.
    For this reason, most C APIs that accept or return arrays, will usually also have some method of communicating the length of the array, usually as an additional parameter of some function. Because .NET APIs usually have no need to do this, the C wrapper for a .NET API in CVI does this for you when it handles .NET arrays. For example, here's what a function signature might look like:
    int CVIFUNC Namespace1_Class1_Test1DArrays (Namespace1_Class1 __instance, int * inA, int __inALength, char *** outA, int * __outALength, Namespace1_Class2 ** refA, int * __refALength, double ** __returnValue, int * ____returnValueLength, CDotNetHandle * __exception);
    Luis

  • Number of elements in a geometry

    Hi All,
    I am wondering if there is any way to enquire on a geometry to determine how many elements it contains. Eg: a polygon with an outer boundary and two inner holes would have three elements. I am guessing that the sdo_elem_info_array would need to be interrogated, but does anyone know of a neat method to do that?
    many thanks for any suggestions!
    Kay

    Hi Andreas,
    Thankyou very much for your reply - you have set me on the right track.
    I am now using the following function to obtain the number of entries in the sdo_elem_info varray:
    create or replace function sdo_elemcount(gt mdsys.sdo_geometry)
    return number
    is begin
    return (gt.sdo_elem_info.count());
    end sdo_elemcount;
    then running as follows to get the number of elements:
    select sdo_elemcount(geom)/3 from table_name where objectid = x;
    dividing by 3 gives me the number of distinct elements in the geometry.
    Thanks for your help Andreas!
    Kay

  • Number of elements in TDMS file

    Is there a way to determine the number of elements in a TDMS file?  The files I am creating have several signals all of the same length.  The only way I can think of is to do this is put it in a loop and read one element at a time until it reaches the end of the file.  But, my files will have millions of elements.  Any suggestions?
    Thanks.
    --Robert

    Thanks Herbert
    For readers having similar problems, here are my experiences:
    It works either without wiring a property name and datatype, as you mentionned before.
    Resulting is a variant array. Result see attached solutionVariant.jpg
    It also works wiring the right datatype as in the TDMS File Viewer and your first explanations:
    Resulting is the channel length as Integer I64 or U64. Datatype constant representation and indicator representation must match!
    See attached solution.jpg
    My error has been wiring a string "I64" as datatype and a string indicator as value indicator. So stupid...
    Regards
    Klaus
    Attachments:
    solutionVariant.jpg ‏30 KB
    solution.jpg ‏8 KB

  • How to check number of elements available in RT FIFO?

    Hi,
        Without using READ FIFO function is there a way to check the number of elements in RT FIFO? I am looking a function like the get queue status function VI.
        Thanks a lot!
        Regards,
        Tom
    Solved!
    Go to Solution.

    RT FIFO Read and Write functions have had a "# elements" output since LabVIEW 8.2.  You should be able to utilize that output to determine how many elements are left in the FIFO.  If you have a version of LabVIEW previous to LabVIEW 8.2, you can utilize the attached VI to determine how many elements are left.
    Regards,
    Keith M.
    Applications Engineer
    Attachments:
    fifo.vi ‏65 KB

  • How to determine number of photos I have?

    I cannot find anywhere in Photoshop Elements where it tells the total of photographs I have in my collection.  The old version told this number in the lower right hand corner.  Is there somewhere in this newer version where I can find how many photos I have without having to count them?  Please help.  Thanks.

    Thanks so much Neale!!!
    In a message dated 2/19/2014 7:05:52 P.M. Eastern Standard Time, 
    [email protected] writes:
    Re:  How to determine number of photos I have?
    created by nealeh (http://forums.adobe.com/people/nealeh)  in Photoshop 
    Elements - View the full  discussion
    (http://forums.adobe.com/message/6137888#6137888)

  • LV 8.5.X: Enum Constant, Number of Elements

    Hello,
    I want to determine the number of elements of an enum constant, is
    that possible at all?
    Thanks and greetings,
    Udo

    parthabe wrote:
    What is the thing behind indexing 2?
    I mean, how will I have to know that when I index 2, I ll get the Enum constant's item count...
    That is buried inside the LabVIEW data-type definition:
    Enumerated 8-Bit Integer
    In the following example of an enumerated 8-bit integer for the items am, fm, and fm stereo, each group of characters represents a 16-bit word. The space enclosed in quotation marks (" ") represents an ASCII space.
    0016 0015 0003 02a m02 fm 09f m" " st er eo
    0016 indicates 22 bytes total. 0015 indicates an enumerated 8-bit integer. 0003 indicates there are three items.
    Here's the VI I was talking about.
    Ton
    Message Edited by TonP on 06-10-2008 09:15 AM
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

  • How to get the number of elements in a tilelist

    I'm writing test cases for a flex application using FlexSelenium and I need to get the number of elements displayed in the tilelist.
    I know that that the tilelist is fed by an array. but i can't access that array from my test case.
    Can anyone tell me how I can get the number of elements in a tilelist on the application? which property of the tilelist can provide that number?

    try tileList.dataProvider.length;

  • How to get the number of elements in DB

    Could you tell me how to get the number of elements in DB??
    My code to get the number is below, but I think it is not efficient
    DB->cursor(DB, NULL, &cursorp, 0);
    while ((ret = cursorp->c_get(cursorp, &key, &data, DB_NEXT)) == 0)
    count++;
    --------------------------------------------------------------------------------------------------------------

    Hi,
    The most efficient way to get a count from the database is using the DB->stat API (http://docs.oracle.com/cd/E17076_02/html/api_reference/C/dbstat.html)
    The code will be something like:
            DB *dbp;
            DB_BTREE_STAT *statp;
            int ret;
            /* Print out the number of records in the database. */
            if ((ret = dbp->stat(dbp, NULL, &statp, 0)) != 0) {
                    dbp->err(dbp, ret, "DB->stat");
                    goto err1;
            printf("%s: database contains %lu records\n",
                progname, (u_long)statp->bt_ndata);
            free(statp);The code comes from the example included in the distribution at examples/c/ex_btrec.c
    If the database isn't a btree, you should update to the appropriate statistics structure and field.
    It's worth noting that retrieving the count is never a "cheap" operation. The count is not stored in the database - since doing so introduced a single point of contention that creates a bottle neck.
    Regards,
    Alex Gorrod
    Oracle Berkeley DB

  • Number of elements at logical level / odbc driver

    Hi everyone,
    I'm new in BI area and I cannot understand one basic thing.
    I study documentation about BI server, exactly chapter about "creating dimensions" and I'm confused about setting "number of elements at logical level"
    It looks for me that "number of elements at logical level" is static.
    What will be when someone update data in the table and number of elements will be different than number of elements in our logical level?
    example:
    current column with distinct values:
    channel_desc:
    direct sales
    tele sales
    catalog
    internet
    partners
    in this case I set number of elements at logical level 5.
    after a while some update data in the table and our column looks (see below)
    column after update with distinct values:
    channel_desc:
    direct sales
    tele sales
    catalog
    internet
    partners
    others (added value)
    Does it mean that I have to change it to current numbers of elements?
    I'm sure that this is misunderstanding in my case, but I don't know where?
    Second problem which I have:
    BI with oracle database is on linux
    client software on windows
    I can import data from database like sybase or flat files to the physical model, I can view data, but when I create whole model (physical, bussines model and mapping, presentation) and I try access data from "Answers" I have this error:
    "Data source name not found and no default driver specified"
    regards
    Bart

    Number of elements is just an indication used by the BI Server (e.g. when generating LOV's in Answers). It won't cause any problems when it doesn't hold the exact number of elements available in the dataset.

  • Number of elements - Dimensional Hierarchy

    Hi,
    In a *'Dimensional Hierarchy'*, while creating a new *'Parent level'*, a 'Logical Level' dialogue box prompts for entering *'Number of elements at this Level'*+. What is its significance ?
    What is achieved by+ *'Number of elements at this Level'* +?+
    Thanks in Advance & Regards,
    Deeba

    Hi deeba,
    Its not mandatory to specify the number of elements in hierarchy....if you wont mention also by default it takes the value of 1.....Above vino gave you the link for explanation.
    Hope it helps you...Award points and close the thread.
    By,
    KK

  • Write two functions to find the the number of elements in a linked list?

    I am trying to Write two functions to find the the number of elements in a linked list. One method using recursion and One method using a loop...
    //The linked List class is Represented here.
    public class lp {
    public int first;
    public lp rest;
    public lp(int first1, lp rest1)
    first = first1;
    rest = rest1;
    The program i wrote so far is
    import java.util.*;
    import linklist.lp;
    public class listCount{
    //loop function
    public static void show_list(lp list)
    int counter = 0;
    while(list != null)
    list = list.rest;
    counter++;
    System.out.println ("length computed with a loop:" + counter);
    //recursive function
    public static int recursive_count(lp list)
    if (list.first == null)
    return 0;
    else
    return recursive_count(list.rest) + 1;
    //main method
    public static void main (String args[])
    lp list1 = new lp(1, new lp(2, new lp(3, null)));
    show_list(list1);
    System.out.println("length computed with a recursion:" +
    recursive_count(list1));
    at the if (list.first == null) line i get the error " incomparable types:
    int and <nulltype>" I know this is a beginners error but please
    help...What should I do?

    byte, char, short, int, long, float, double, and boolean are primitives, not objects. They have no members, you cannot call methods on them, and they cannot be set to or compared with null.

Maybe you are looking for

  • HP 1510 all in one printer will not install

    I have just purchased a new 1510 all in one printer. I have installed the printer software from the CD supplied. However when I try to run the printer HP assitant comes on with run time error. I have tried to uninstall and reinstall the printer many

  • CS6 Bridge Under Windows 8 Slow Response

    When I use CS6 Bridge in Windows 8 (64 bit) it takes about 10 seconds to open a folder.  I select an image from the grid and press the spacebar to see it full size.  It takes another 10 seconds.  If I go to the Menu Bar and click on an item such as W

  • Access current user's manager name in the console application ( through Client object model)

    Hi Guys, Is there any way to retrieve current logged-in user's Manager name in the console application. As I don't have access to the server where SharePoint 2010 is installed so I wanted to access through client object model. arun singh

  • Restore RMAN backup from tape

    I have to restore the RMAN full backup from tape to new host to a previous date say March 1st. My target database RMAN retention period is 28 days, today is 11th May. Is it possible to restore the obsolete database from tape backup to new host as of

  • AC 5.3 CUP - authorization for CUP's users

    Dear Friends, We are trying to see what are the authorizations that we should give the users who are going to use the CUP system. We have some users who are approvers. We want to give them the authorizations maintain and view only the request that th