Table.sort - is it broken, or am I doing something wrong?

sometimes, what should be the last element is not being put in the correct position (last) (all others are in the correct order) - no matter what I do, and I have to resort to this function, which works flawlessly:
function Table:sort( t, func )
    local tc = self:copy( t ) -- make shallow copy
    tc[#tc + 1] = "___dUmMy___" -- 3 underscores on each side.
    table.sort( tc, func )
    local index = 1
    for i = 1, #tc do
        if tc[i] ~= "___dUmMy___" then
            t[index] = tc[i]
            index = index + 1
        else
            -- skip it.       
        end
    end
    t[#tc] = nil -- shouldn't be necessary, but cheap insurance...
end
i.e. add an extra dummy element to the table, then sort it using the same sort function, then remove the dummy element.
Its like table.sort makes one iteration too few, unless the dummy is there to force it, or something...
This is driving me crazy!
Any ideas?

So, I figured it out.
Sometimes I want the exact opposite order than is (reliably) possible given the table sort algorithm.
If, in a table sort function, one replaces:
return order
with
return not order
(in a perfectly working sort function), it reverses the order of the sort but may not handle the last element properly.
The reason is this:
The table sort return value is determining whether to swap two values or not to swap them, it is *not* determining absolute ordering - if it were, then returning true would mean order one way, and returning false would mean order the opposite way.
Enough talk - test plugin: http://www.robcole.com/_temp/TestLrPlugins/Scratch_LrPlugin_0.0.zip
(Instructions: In plugin manager, click 'Local Test' button. Source code is in ExtendedManager.lua (tableSortTest function) and Framework/Data/Table.lua (reverseSortCopy method).
Rob

Similar Messages

  • Is smserialport broken or am I doing something wrong?

    I'm trying to configure a serial port and I keep getting blown off by smserialport. I have tried using the SMC gui and that shows no ports and gives me no actions to add a port. So I went back to the command line :
    Firstly, it won't list ports :
    # ./smserialport list -u root -p xxx --
    Loading Tool: com.sun.admin.serialmgr.cli.SerialMgrCli from sinister
    Login to sinister as user root was successful.
    Download of com.sun.admin.serialmgr.cli.SerialMgrCli from sinister was successful.
    An internal inconsistency was detected at NoListData. Exiting.
    So I assume it was badly coded and noone ever considered that there wouldn't be a port, so forgot to have code to deal with that.
    I have devices ttya and ttyb :
    # ls -l tty?
    lrwxrwxrwx 1 root root 26 Sep 2 18:37 ttya -> ../devices/isa/asy@1,3f8:a
    lrwxrwxrwx 1 root root 26 Sep 2 18:37 ttyb -> ../devices/isa/asy@1,2f8:b
    So, I try and configure one of those for a terminal
    (I have seen a link on Sunsolve for adding a serial port with smserialport, but I don't have enough privs to read it...)
    What I have tried so far is based on the man page :
    # ./smserialport configure -u root -p xxx -- -n a -b 19200 -t vt100
    Loading Tool: com.sun.admin.serialmgr.cli.SerialMgrCli from sinister
    Login to sinister as user root was successful.
    Download of com.sun.admin.serialmgr.cli.SerialMgrCli from sinister was successful.
    Error: Invalid serial port name: a
    Usage:
    smserialport configure [-H host:port] [-u user] [-p password] [-r rolename] [-l rolepassword] [-D domain] --
    -n port_name [-x device=terminal] [-b baudrate] [-t terminal_type] [-l login_prompt] [-c Comment]
    -n port_name [-x device=modemdialin] [-b baudrate] [-t terminal_type] [-l login_prompt] [-c Comment]
    -n port_name [-x device=modemdialout] [-b baudrate] [-t terminal_type] [-l login_prompt] [-c Comment]
    -n port_name [-x device=modemdialinout] [-b baudrate] [-t terminal_type] [-l login_prompt] [-c Comment]
    -n port_name [-x device=initializeonly] [-b baudrate] [-t terminal_type] [-l login_prompt] [-c Comment]
    So what am I missing? It looks to me like it can't detect my serial ports in /dev, which I can do with an 'ls' command.
    Thanks,
    Max

    So, I figured it out.
    Sometimes I want the exact opposite order than is (reliably) possible given the table sort algorithm.
    If, in a table sort function, one replaces:
    return order
    with
    return not order
    (in a perfectly working sort function), it reverses the order of the sort but may not handle the last element properly.
    The reason is this:
    The table sort return value is determining whether to swap two values or not to swap them, it is *not* determining absolute ordering - if it were, then returning true would mean order one way, and returning false would mean order the opposite way.
    Enough talk - test plugin: http://www.robcole.com/_temp/TestLrPlugins/Scratch_LrPlugin_0.0.zip
    (Instructions: In plugin manager, click 'Local Test' button. Source code is in ExtendedManager.lua (tableSortTest function) and Framework/Data/Table.lua (reverseSortCopy method).
    Rob

  • Hi there, I seem to be losing emails from my inbox - they just disappear! Is this some sort of a bug or am I doing something wrong? thanks

    I also just reactivated my MS outlook & same thing seems to be happening...does Outlook somehow sync to Thunderbird?
    Please help!

    No/yes
    If its an IMAP account, they both read the same account.
    If its a POP account check that you leave it on server and don't delete after x days.
    Check your account on server as well as on both your clients.

  • Why does it open all pages that I have in the tray when I try and open a new one? Sort of flustrating. I must have done something wrong because it did not do that in the past. Thanks for any help in correcting the problem. in English

    I keep about 5 pages open at all times in the tray and when I open a new page all open with the new one on the top of the stack. My computer did not do that in the past. What did I do and how do I correct the problem? Any help would be appreciated.

    You may submit feedback directly to the Advocacy team through the following page:
    * [https://input.mozilla.org/feedback/ Submit your Feedback]
    The [https://wiki.mozilla.org/Advocacy User Advocacy] team reviews all feedback and reports on the findings to the product teams and relevant parties, helping to influence and shape our products.

  • Af:table sorting when immediate='true' bug

    Where can I find the patch to fix the problem of sorting an af:table when immediate='true'?

    No I don't have a bug number, I've found that this is a bug based on this thread <a href src='BUG:  ADF FACES 10.1.3_04: Table sort broken if immediate="true" but I have no idea what the number is or where to find the patch for it.
    This is a really irritating bug. I want to have sorting on my tables but if I can't put immediate='true' on the table then other components on the page will fire their validation.

  • Text Overlapping/Wrapping Issue in BSP(Table Sorter Using JQUERY)

    Hi ,
    I have a requirement to add a new column in existing table which has been built by Table Sorter method in JQUERY.
    I have added the new column but the issue is value for the new column is populated  on next line of the table.
    This could be a simple width issue, but i don't know JAVA much.Attached the image for reference.
    Code i have used is:
    <input type="text" name="t_rbclaim[<%= lv_tabix%>].reason" size="3" maxlenth="3" wrapping = "true"
         onBlur="javascript:this.value=this.value.toUpperCase();" value="<%= w_rbclaim-reason%>">
    Please let me know how to modify the above code in better way.

    Hi Raja,
    Can you please help on this problem. I want to know whether there is any funciton module to convert the univercel character set code (HTML Codepage) page to SAP codepage. We are going to use ECC 6.0 which is unicode system for background R/3. So we can get the correct character format if identify the correct conversion method.
    Please let me know if any information and expect some information on this.
    Regards,
    Saravanan V

  • Line style of Word tables is ignored. Broken lines or dotted lines appear as uninterrupted lines

    Bug in Adobe XI:
    The line style of Word tables is ignored. Broken lines or dotted lines in Word tables are shown as normal uninterrupted lines in PDF file.
    For example, in my Word document I choose the following line styles in tables: dotted line (.........................) or broken line ( - - - - - - - - - - - - ).
    In the PDF file, all lines are shown as normal uninterrupted lines (__________________), even if I zoom in 800% or more.
    Is there a solution for this problem? (In FreePDF, it works well, but FreePDF has other disadvantages and therfore is no solution for me.)

    Ok 1st one. The warning restriction message relates to this line in main.cf:
    smtpd_helo_restrictions = permit_sasl_authenticated  permit_mynetworks  check_helo_access hash:/etc/postfix/helo_access  reject_non_fqdn_hostname  reject_invalid_hostname  permit reject_invalid_helo_hostname
    The last reject occurs after the single word "permit" and is ignored.
    However, that's not the problem.
    I'm not exactly sure what's happening, but this might be a clue.
    It would appear that either postfix is not being able to create the socket for private/policy or it's somehow created with the wrong permissions.  You might need to ramp up the debug level to get a better idea.
    You could check if it's being created by "netstat -a | grep private/policy" in terminal.
    My guess is that it's not being created because there is no setup statement in your master.cf file, but I don't understand why postfix would be looking for it if it isn't set up.  Private/policy I think relates to grey listing.  Maybe gives you a hint.

  • Custom table model, table sorter, and cell renderer to use hidden columns

    Hello,
    I'm having a hard time figuring out the best way to go about this. I currently have a JTable with an custom table model to make the cells immutable. Furthermore, I have a "hidden" column in the table model so that I can access the items selected from a database by their recid, and then another hidden column that keeps track of the appropriate color for a custom cell renderer.
    Subject -- Sender -- Date hidden rec id color
    Hello Pete Jan 15, 2003 2900 blue
    Basically, when a row is selected, it grabs the record id from the hidden column. This essentially allows me to have a data[][] object independent of the one that is used to display the JTable. Instinctively, this does not seem right, but I don't know how else to do it. I know that the DefaultTableModel uses a Vector even when it's constructed with an array and I've read elsewhere that it's not a good idea to do what I'm trying to do.
    The other complication is that I have a table sorter as well. So, when it sorts the objects in the table, I have it recreate the data array and then set the data array of the ImmutableTableModel when it has rearranged all of the items in the array.
    On top of this, I have a custom cell renderer as well. This checks yet another hidden field and displays the row accordingly. So, not only does the table sort need to inform the table model of a change in the data structure, but also the cell renderer.
    Is there a better way to keep the data in sync between all of these?

    To the OP, having hidden columns is just fine, I do that all the time.. Nothing says you have to display ALL the info you have..
    Now, the column appears to be sorting properly
    whenever a new row is added. However, when I attempt
    to remove the selected row, it now removes a seemingly
    random row and I am left with an unselectable blank
    line in my JTable.I have a class that uses an int[] to index the data.. The table model displays rows in order of the index, not the actual order of the data (in my case a Vector of Object[]'s).. Saves a lotta work when sorting..
    If you're using a similar indexing scheme: If you're deleting a row, you have to delete the data in the vector at the INDEX table.getSelectedRow(), not the actual data contained at
    vector.elementAt(table.getSelectedRow()). This would account for a seemingly 'random' row getting deleted, instead of the row you intend.
    Because the row is unselectable, it sounds like you have a null in your model where you should have a row of data.. When you do
    vector.removeElementAt(int), the Vector class packs itself. An array does not. If you have an array, when you delete the row you must make sure you dont have that gap.. Make a new array of
    (old array length-1), populate it, and give it back to your model.. Using Vectors makes this automatic.
    Also, you must make sure your model knows the data changed:
    model.fireTableDataChanged(); otherwise it has no idea anything happened..
    IDK if that's how you're doing it, but it sounds remarkably similar to what I went thru when I put all this together..

  • Can't add row using table sorter

    I had a jtable with my own mytableModel that implements AbstractTableModel. In mytableModel, I have addRow, removeRow... so I can delete/add row dynamically by calling mytableModel.addRow(..). Everything works fine.
    However, after I added the table sorter and table map (got the code from the tutorial).
    MyTableModel myModel = new MyTableModel();
    TableSorter sorter = new TableSorter(myModel);
    JTable table = new JTable(sorter);
    sorter.addMouseListenerToHeaderInTable(table);
    Now, when i call mytableModel.addRow(..), it doesn't work anymore. It doesn't add a row anymore, why?
    Thank you so much for your help.

    I don't have a addRow method in TableSorter. My addRow method is in myTableModel. So, when I need to addRow, I called myTableModel.addRow, In my addRow method, I have fireTableRowsInserted method. This used to work using integrating with TableSorter.
    Do I need to move all my addRow, addCol....DelRow... to TableSorter? The table data are stored in myTableModel. I guess I really doesn't know how the TableSorter work :(
    Thanks

  • Table Sorter Not working in EP 7.01

    Hi All,
    The table sorter stopped working in ep 7.01.
    Can anyone comment why?
    Are there any notes or patches to be applied?
    Thanks and Regards,
    Nuzhat

    Hi Shanti,
    Thanks for replying.
    I am working on WD for Java.
    Can you please give me your table sorter Java file?
    I think there may be issues in versions.
    Previous server was ep 7.00 and now when code is moved to ep 7.01 sp05 patch 1, the table sort doesnt seems to work. even though I checked all the codes are there in the new system.
    Thanks and Regards,
    Nuzhat

  • Table.Sort only sorting records in preview pane

    I have the following M query:
    let
        OrgIdParameter = Excel.CurrentWorkbook(){[Name="ClientFilter"]}[Content],
        OrgIdValue = OrgIdParameter{0}[Column2],
        Source = Sql.Database("JOHNSQLD53", "EnterpriseAnalytics"),
        dbo_vFactEngrgServiceLocMonthlyAsOfSnapshot = Source{[Schema="dbo",Item="vFactEngrgServiceLocMonthlyAsOfSnapshot"]}[Data],
        #"Filtered Rows" = Table.SelectRows(dbo_vFactEngrgServiceLocMonthlyAsOfSnapshot, each [BeProspectClientOrgId] = OrgIdValue),
        #"Sorted Rows" = Table.Sort(#"Filtered Rows",{{"SnapshotYear", Order.Ascending}})
    in
        #"Sorted Rows"
    however, the sort is working on the records that show in the preview pane (about 36 records), then the data goes back to being unsorted in the rest of the table when loaded in power pivot (224 rows).
    any idea why?

    I believe that Power Pivot does not reliably preserve the input sort of the data; this is a feature of the data model, not of Power Query.

  • EIT SSHR Table sorting

    Hi all,
    I have successfully personalized the EIT SSHR screen to display one of the configured EIT on a custom responsibility using a custom function(so that I can do personalization on function level without affecting other EIT screens).
    Now my challenge is that, when I click on the menu function, it takes me to the people search page, I do a search and select a employee, then it shows me the list of existing EIT records with an option of add, update and delete. Here, I need to show the existing records in a sorted order. I need the latest entry entered to appear in the top. If this is not possible, it would be great if I can have the table sorted as per one of the segment value.
    Is there a way to do this. Can someone help me in doing this and let me know the steps to do the same.
    Cheers
    Arun

    I think Tomahawk is the way to go here.
    Tomahawk allows sorting of data in the data table.
    For action based on row selection, you need to invoke java script function
    using rowOnClick attribute of t:dataTable and then make a hidden command button "click" from
    the java script.
    Regards,
    Joshua

  • CS4 - Still no table sorting

    OK -- We're up to version 6 now with InDesign and Adobe still hasn't incorporated a built-in table row sorting feature? Is it me, or does anyone else think this is absolutely absurd.
    It seems table sorting would be a big issue not just for the technical publishing crowd...but maybe I'm wrong.
    Unless I'm mistaken, from what I can gather there are 3 methods that people are currently using to sort their table row data:
    1) FREE - Manually sort the data in a Word table or Excel, then paste back into ID (which of course loses most formatting and applied styles)
    2) FREE - Use a Script like:
    http://www.kahrel.plus.com/indesign/tablesort.html
    3) EXPENSIVE - Purchase a plugin like:
    http://www.woodwing.com/en/Smart_Styles
    Anybody have any other solutions? We would love to see an inexpensive plugin that does what Smart Styles offers (without all of the other non-sorting features)...or do we have to wait another year for CS5 to find out if this feature finally makes it in.

    The several-year gap in postings on this thread, may indicate that there's not a lot of interest in having the feature built into InDesign. However, if you really need it now, look into the commercial Active Tables plug-in from dtptools.com. There's a free trial. Besides sorting, it can perform many spreadsheet functions within ID tables.
    [/EDIT] I forgot to mention that you can add your formal support for building the feature into ID here: Wishform.[/EDIT]
    HTH
    Regards,
    Peter
    Peter Gold
    KnowHow ProServices
    moyler0316 wrote:
    This would be an EXTREMELY helpful feature. I have to sort at least one table in nearly every technical publication I create. These are 2-3 pages + long, so I'd much rather click a button than do it by hand or try 1/2 a dozen different work arounds. 
    Message was edited by: peter at knowhowpro

  • EA 19 Table Sorting

    I've downloaded adf faces ea19. In its documentation is descripted
    this feature:
    <<Aspect API
    A new Aspect API (this name will likely be changed in upcoming
    releases) lets component changes
    persist across requests. For example, the sort order of a table or
    expansion of a tree can
    automatically be restored for you when you return to a page. This API
    is currently not active by
    default, but has been turned on in the demo bundle with the
    oracle.adf.view.faces.ASPECT_PERSISTENCE
    context parameter. See the Javadoc and the enclosed demos for more
    information.>>
    I'm very interested to preserve the sort order in my pages with
    tables, so I've add the follow lines in web.xml:
    <context-param>
    <param-name>oracle.adf.view.faces.CHANGE_PERSISTENCE</param-name>
    <param-value>session</param-value>
    </context-param>
    But I think ASPECT_PERSISTENCE doesn't work.
    The table sort order is not preserved, no change respect the
    precedent adf version.
    Anyone with some ideas about this problem?
    Thank you

    I think Tomahawk is the way to go here.
    Tomahawk allows sorting of data in the data table.
    For action based on row selection, you need to invoke java script function
    using rowOnClick attribute of t:dataTable and then make a hidden command button "click" from
    the java script.
    Regards,
    Joshua

  • Table sorting

    Hello All,
    I already implement table sorting in my application.How can i trigger a table sort action on a particular column after I have compeleted some other action?
    Thanks

    Use IWDNode.sortElements(Comparator).
    The Comparator instance passed to this method should cast its arguments to the node element interface and compare them by the attribute displayed in the particular column.
    Say your node is named "Employees" and the attribute is "Name" and has type "String", then it looks like
    Comparator comparator = new Comparator()
      public int compare(Object x1, Object x2)
        IEmployeesElement e1 = (IEmployeesElement ) x1;
        IEmployeesElement e2 = (IEmployeesElement ) x2;
        return e1.getName().compareTo(e2.getName());
    node.sortElements(comparator);
    Armin

Maybe you are looking for

  • Home/sleep button is not working properly. why?

    i just bought i new ipod on ebay. But home and sleep button on my ipod touch 4th generation is not working properly after long sleep time. but it works properly when its plugged-in for charging..why? how can i solve it?

  • Itunes Error 7 Windows Error 126

    After having to remove iTunes from my computer, I have tried to reinstall it several times without luck getting itunes error 7 windows error 126. I have tried uninstalling and reinstalling at least five times and keep getting the same message! I real

  • Lm_sensors upgrade error

    I try to upgrade lm_sensors and I get this error: Targets: lm_sensors-2.10.1-2 Total Package Size: 0.3 MB Proceed with upgrade? [Y/n] y checking package integrity... done. loading package data... done. checking for file conflicts... error: the follow

  • HR ABAP Learning.

    Hi Friends,       Iam working as an ABAP Consultant.       I want to enhance it to HR ABAP. <removed - requesting copyrighted material is prohibited > regards, phaneendra p Edited by: Arun Varadarajan on Apr 7, 2009 3:35 PM

  • Calling Two Functions

    Hi, I have two functions to call when the form is submitted how to do this. <form action="xxx" onsubmit =fun1()> how to include other onsubmit please give syntax