Heap Sort

Hi, I'm writing a code for Heap Sort, to sort an array of Comparables from 1 to n
But it is not working, can some one please look at my code and tell me where I'm wrong, Please.........
public class HeapSort {
     //Sorts an array of data of the specified type, using the heap sort algorithm,
     //and returns the number of comparisons made.
     public void heapSort(java.lang.Comparable[] data){
          int n=data.length-1;
          buildMaxHeap(data);
          for(int i=n;i>=2;i--){
               Comparable temp=data[1];
               data[1]=data;
               data[i]=temp;
               --n;
               maxHeapify(data,1,n);
     //Sorts the first heapSize elements of array A, using heap sort.
     //Assumes heapSize is less than or equal to A.length.
     public void heapSort(java.lang.Comparable[] A, int heapSize) {
          for(int i=A.length-1;i>1;i--) {
               Comparable temp=A[1];
               A[1]= A[i];
               A[i]=temp;
               --heapSize;
               maxHeapify(A,1,heapSize);
     public void buildMaxHeap(java.lang.Comparable[] A){
          int hs=A.length-1;
          for(int i=hs/2;i>1;i--){
               maxHeapify(A,i,hs);
     public void maxHeapify(java.lang.Comparable[] A, int badIndex, int heapSize){
          int left=2*badIndex;
          int right=2*badIndex+1;
          int largest;
          if(left<=heapSize && A[left].compareTo(A[badIndex]) > 0) {
               largest=left;
          else {
               largest=badIndex;
          if(right <=heapSize && A[right].compareTo(A[largest])>0) {
               largest=right;
          if(largest!=badIndex){
               Comparable temp=A[badIndex];
               A[badIndex]=A[largest];
               A[largest]=temp;
               maxHeapify (A,largest,badIndex);

public class HeapSort {
     //Sorts an array of data of the specified type, using the heap sort algorithm,
     //and returns the number of comparisons made.
     public void heapSort(java.lang.Comparable[] data){
          int n=data.length-1;
          buildMaxHeap(data);
          for(int i=n;i>=2;i--){
               Comparable temp=data[1];
               data[1]=data;
               data[i]=temp;
               --n;
               maxHeapify(data,1,n);
     //Sorts the first heapSize elements of array A, using heap sort.
     //Assumes heapSize is less than or equal to A.length.
     public void heapSort(java.lang.Comparable[] A, int heapSize) {
          for(int i=A.length-1;i>1;i--) {
               Comparable temp=A[1];
               A[1]= A[i];
               A[i]=temp;
               --heapSize;
               maxHeapify(A,1,heapSize);
     public void buildMaxHeap(java.lang.Comparable[] A){
          int hs=A.length-1;
          for(int i=hs/2;i>1;i--){
               maxHeapify(A,i,hs);
     public void maxHeapify(java.lang.Comparable[] A, int badIndex, int heapSize){
          int left=2*badIndex;
          int right=2*badIndex+1;
          int largest;
          if(left<=heapSize && A[left].compareTo(A[badIndex]) > 0) {
               largest=left;
          else {
               largest=badIndex;
          if(right <=heapSize && A[right].compareTo(A[largest])>0) {
               largest=right;
          if(largest!=badIndex){
               Comparable temp=A[badIndex];
               A[badIndex]=A[largest];
               A[largest]=temp;
               maxHeapify (A,largest,badIndex);

Similar Messages

  • Relationship between Dynamic Memory Heap and Heap Data Structure

    This question is not strictly related to Java, but rather to programming in general, and I tend to get better answers from this community than any where else.
    Somehow, my school and industry experience have somehow not given me the opportunity to explore and understand heaps (the data structure), so I'm investigating them now, and in particular, I've been looking at applications. I know they can be used for priority queues, heap sorts, and shortest path searches. However, I would have thought that, obviously, there must be some sort of relationship between the heap data structure, and the dynamic memory heap. Otherwise, I can think of no good reason why the dynamic memory heap would be named "heap". Surprisingly, after searching the web for 90 minutes or so, I've seen vague references, but nothing conclusive (trouble seems to be that it's hard to get Google to understand that I'm using the word "heap" in two different contexts, and similarly, it would not likely understand that web authors would use the word in two different contexts).
    The Java Virtual Machine Spec is silent on the subject, as "The Java virtual machine assumes no particular type of automatic storage management system, and the storage management technique may be chosen according to the implementor's system requirements."
    I've seen things like:
    [of dynamic memory] "All the blocks of a particular size are kept in a sorted linked list or tree (I extrapolate that sorted tree could imply heap)"
    [of dynamic memory] "The free and reserved areas of memory are maintained in a data structure similar to binary trees called a heap"
    [of dynamic memory] "This is not related to the heap data structure"
    [of dynamic memory] "Not to be confused with the data structure known as a "heap"
    [of data structure] "Not to be confused with the dynamic memory pool, often known as TheHeap"
    At this point, I've come to surmise that some (but not all) memory management algorithms use heaps to track which (pages? blocks? bytes?) of memory are used, and which are not. However, the point of a heap is to store data so that the max (or min) key is at the root of the heap. But we might want to allocate memory of different sizes at different times, so it wouldn't make sense to key on the amount of available memory in a particular region of the free store.
    I must assume then that there would be a different heap maintained for each size of memory block that can be allocated, and the key must have something to do with the attractiveness of the particular memory block in the heap (perhaps the lowest address, resulting, hopefully, in growing the free store space less often, leaving more space for the stack to grow, or perhaps keyed based on the fragmentation, to hopefully result in less fragmentation, and therefore more efficient use of the memory space, or perhaps based on page boundaries, keeping as much data in the same page as possible, etc).
    So at this point, I have a few questions I've been unable to resolve completely:
    1. Am I correct that the heap was so named because (perhaps at one point in time), a heap is/was commonly used to track the available memory in the free store?
    2. If so, would it be correct that there would be a heap per standard block size?
    3. Also, at what level of granularity would a heap typically be used (memory page, memory blocks, individual words (4-bytes))?
    4. What would be the most likely property one would use as a key. That is, what makes the root item on the heap ideal?
    5. Would a industrial strength system like the jvm use a (perhaps modified or tuned) heap for this sort of task, or would this typically be too naive for an real world solution today?
    Any insight would be awesome!
    Thanks,
    A.

    jschell wrote:
    I think you are not only mixing terms but domains.
    For starters the OS allocs memory. Applications, regardless of language, request memory from the OS and use it in various ways.
    There are many variations of the term "heap" like the following.
    [http://en.wikipedia.org/wiki/Heap_(data_structure)]
    [http://en.wikipedia.org/wiki/Dynamic_memory_allocation]
    A java VM will request memory from the OS (from a 'heap') and use it in its application 'heap' (C/C++) and then create the Java 'heap'. There can be variations of that along the way that can and likely will include variations of how each heap is used, potentially code that creates its own heap, and potentially other allocators which use something which is not a heap.This last part, I find a bit confusing. By "use something which is not a heap", do you mean the heap data structure, or the dynamic memory pool meaning of heap? If the former, then you would be implying that it would be common for a heap data structure to be used to manage the heap dynamic memory pool. If the latter, what would this "something which is not a heap" be? The best definition of "heap" I've found simply states that it is a pool of memory that can be dynamically allocated. If there is some other way of allocating dynamic memory, then it would suggest that the previous definition of "heap" is incomplete.
    >
    So to terms.
    1. Am I correct that the heap was so named because (perhaps at one point in time), a heap is/was commonly used to track the available memory in the free store?Which 'heap'? The VM one? It is probably named that because the implementors of the Sun VM were familar with how C++ and Smalltalk allocated memory.Okay, but that begs the question, was the heap in C++ and/or Smalltalk so named for the above queried reason?
    >
    2. If so, would it be correct that there would be a heap per standard block size?Not sure what you are referring to but probably a detail of the implementation. And since there are different levels the question doesn't mean much.
    However OS allocations are always by block if that helps. After that it requires making the question much, much more specific.
    3. Also, at what level of granularity would a heap typically be used (memory page, memory blocks, individual words (4-bytes))?Again not specific enough. A typical standard implementation of heap could not be at the word level. And it is unlikely, but not impossible, that variations would support word size allocations.
    The VM heap might use word boundaries (but not size), where the application heap certainly does (word boundary.)My understanding of it is that the application would request blocks from the OS, and then something like malloc would manage the memory within the allocated blocks. malloc (or whatever equivalent Java uses) would have to keep track of the memory it has allocated somehow, and I would think it would have to do this at the word level, since it's most commonly going to allocate memory at the word level to be references to other objects, etc.
    So I guess my question here would really be, if the dynamic memory heap is so named because there has been a memory management strategy that relied upon a heap data structure (which I've found no proof, but have found some suggestive literature), then would that probably have applied at the OS Page Fault level, tracking allocated blocks, or would that have applied at the malloc level, allocating individual words as necessary?
    >
    4. What would be the most likely property one would use as a key. That is, what makes the root item on the heap ideal?"Key" is not a term that will apply in this discussion.
    You appear to be referring to strategies for effective allocation of memory such as allocations from different regions by size comparison.
    It is possible that all levels might use such an allocator. General purpose applications do not sort allocations though (as per your one reference that mentions 'key'.) Sorry, I got the term "key" from an article I read regarding heaps, that indicates that a "key" is used to sort the elements, which I guess would be a more generalized way to make a heap than assuming a natural ordering on the elements in the heap. I'm not sure if the terminology is standard.
    >
    5. Would a industrial strength system like the jvm use a (perhaps modified or tuned) heap for this sort of task, or would this typically be too naive for an real world solution today?Again too indefinite. The Sun VM uses a rather complicated allocator, the model for which originated after years of proceeding research certainly in Smalltalk and in Lisp as well, both commercially and academically.
    I am sure the default is rules driven either explicitly or implicitly as well. So it is self tuning.
    There are command line options that allow you to change how it works as well.I guess perhaps I could attempt to clarify my initial question a bit.
    There is a 1:1 correspondence between the runtime stack, and a stack data structure. That is, when you call a function, it pushes a stack frame onto the runtime stack. When you return from a function, it pops a stack frame from the runtime stack. This is almost certainly the reasons the runtime stack is named as it is.
    The question is, is there or has there ever been a 1:1 correspondence between some aspect of the dynamic memory heap or how it is managed, and a heap data structure? If so, it would explain the name, but I'm a bit puzzled as to how a heap data structure would be of assistance in creating or managing the dynamic memory heap. If not, on the other hand, then does anybody know where the name "heap" came from, as it applies to the dynamic memory pool?
    A.

  • Nokia N8-00 Belle Refresh - Gallery & Videos probl...

    Hi,
    my first problem is in Albums section. Whenever, every time when I add some photos from Gallery to any existing Album, everything works OK, until restart my phone! After new start/boot  of my N8 all Albums are again empty.
    Please help me with constructive suggestions only (#7370# reset or format aren't decent solutions). Thank you very much in advance.
    Second problem - Suddenly I noted, that Videos lost all my videos. I saw empty screen only and I must copy all videos out and again back to default Video folder, then videos comes back to be visible (unfortunately, except all videos in subfolders). Is it a normality on N8/Belle?
    BTW the default gallery sorting "all into one heap sorted by internal datestamp" makes my life hell!
    Nobody's perfect.

    On my N8-00 is refreshing OK, but missing photos from all Albums after every restart is very nasty bug for me!
    Nobody's perfect.

  • Data comparisons and movements

    I have a Heap Sort using the following code, and I cannot seem to figure out how many data comparisons and data movements there are as the heap is sorted. Does anybody know how to count the number of comparisons and movements?? Please let me know....much appreciated...Thanks :)
    import java.io.IOException;
    import java.util.*; // Calender Class for timing
    public class Heap {
    private MyNode[] heapArray;
    private int maxSize;
    private int currentSize; // number of items in array
    public Heap(int mx) {
    maxSize = mx;
    currentSize = 0;
    heapArray = new MyNode[maxSize];
    public MyNode remove()
    MyNode root = heapArray[0];
    heapArray[0] = heapArray[--currentSize];
    trickleDown(0);
    return root;
    public void trickleDown(int index) {
    int largerChild;
    MyNode top = heapArray[index];
    while (index < currentSize / 2)
    int leftChild = 2 * index + 1;
    int rightChild = leftChild + 1;
    // find larger child
    if (rightChild < currentSize
    heapArray[leftChild].getKey() < heapArray[rightChild]
    .getKey())
    largerChild = rightChild;
    else
    largerChild = leftChild;
    if (top.getKey() >= heapArray[largerChild].getKey())
    break;
    heapArray[index] = heapArray[largerChild];
    index = largerChild;
    heapArray[index] = top;
    public void displayHeap() {
    int nBlanks = 32;
    int itemsPerRow = 1;
    int column = 0;
    int currentIndex = 0;
    while (currentSize > 0)
    if (column == 0)
    for (int k = 0; k < nBlanks; k++)
    System.out.print(' ');
    System.out.print(heapArray[currentIndex].getKey());
    if (++currentIndex == currentSize) // done?
    break;
    if (++column == itemsPerRow) // end of row?
    nBlanks /= 2;
    itemsPerRow *= 2;
    column = 0;
    System.out.println();
    else
    for (int k = 0; k < nBlanks * 2 - 2; k++)
    System.out.print(' '); // interim blanks
    public void displayArray() {
    for (int j = 0; j < maxSize; j++)
    System.out.print(heapArray[j].getKey() + " ");
    System.out.println("");
    public void insertAt(int index, MyNode newNode) {
    heapArray[index] = newNode;
    public void incrementSize() {
    currentSize++;
    public static void main(String[] args) throws IOException {
    int size, i;
    size = 500;
    Heap theHeap = new Heap(size);
    for (i = 0; i < size; i++) {
    int random = (int) (java.lang.Math.random() * 5000);
    MyNode newNode = new MyNode(random);
    theHeap.insertAt(i, newNode);
    theHeap.incrementSize();
    System.out.println(size+" random numbers are currently being generated...");
    for (i = size / 2 - 1; i >= 0; i--)
    theHeap.trickleDown(i); // creates the heap
    System.out.print("\nRandom Numbers in a Heap: ");
    theHeap.displayArray(); // prints the heap
    long time1000start = new Date().getTime() ; // this makes a new Date object and then sets the long integer value of the Date object
    // ******************* START - sorting numbers *******************
    for (i = size - 1; i >= 0; i--)
    MyNode biggestNode = theHeap.remove();
    theHeap.insertAt(i, biggestNode);
    // ******************* END - sorting numbers *******************
    long time1000end = new Date().getTime() ; // this makes a new Date object and then sets the long integer value of the Date object
    double timediff1000m = (time1000end - time1000start); // difference of time in milliseconds
    double timediff1000s = ((time1000end - time1000start) / 1000); // difference of time in seconds
    System.out.print("\nRandom Numbers in a Sort: ");
    theHeap.displayArray(); // prints the numbers in increasing order
    System.out.print("\nStart Time of Sort: "+time1000start);
    System.out.print("\nEnd Time of Sort: "+time1000end);
    System.out.print("\nTime to Complete Sort: "+timediff1000m+" milliseconds or "+timediff1000s+" seconds.");
    } // end main method
    } // END project :)

    I never miss class....my instructor gave us the assignment of making a heap sort and he told us to use code off the internet as a resource because the only sorting we have done so far is bubble.....this was a research project, for my instructor to see if we can use the internet as an effective resource to put together a program and learn about a differnet type of sorting.....everyone in the class got a different type of sort (merge, quick, insertion, etc...). i have put the program together and customized it to my needs based on my knowledge.....the last thing i am having trouble with is my counting of comparisons and data movements. Can you please help me finish up my program.

  • Which is a efficient Data Structure to store data in a file

    I want tostire a data in file in sorted order. I am thinking about Bainary Search tree & heap sort Which is efficient technique. Please reply..

    which is the best data structure to be used in Thread
    pool to store the thread instances? and why ?
    I have seen lots of people using Queue....Why do you ask? You do know that there are thread pool classes in Java 5?
    Kaj

  • Heapsort

    Hi, I'm trying to implement the Heapsort algorithm, but it is not sorting properly, can anyone please review.
    I'm sorting an array from 1 to n
    public class HeapSort {
         //Sorts an array of data of the specified type, using the heap sort algorithm,
         //and returns the number of comparisons made.
         public void heapSort(java.lang.Comparable[] data){
              int n=data.length-1;
              buildMaxHeap(data);
              for(int i=n;i>=2;i--){
                   Comparable temp=data[1];
                   data[1]=data;
                   data[i]=temp;
                   --n;
                   maxHeapify(data,1,n);
         //Sorts the first heapSize elements of array A, using heap sort.
         //Assumes heapSize is less than or equal to A.length.
         public void heapSort(java.lang.Comparable[] A, int heapSize) {
              for(int i=A.length-1;i>1;i--) {
                   Comparable temp=A[1];
                   A[1]= A[i];
                   A[i]=temp;
                   --heapSize;
                   maxHeapify(A,1,heapSize);
         public void buildMaxHeap(java.lang.Comparable[] A){
              int hs=A.length-1;
              for(int i=hs/2;i>1;i--){
                   maxHeapify(A,i,hs);
         public void maxHeapify(java.lang.Comparable[] A, int badIndex, int heapSize){
              int left=2*badIndex;
              int right=2*badIndex+1;
              int largest;
              if(left<=heapSize && A[left].compareTo(A[badIndex]) > 0) {
                   largest=left;
              else {
                   largest=badIndex;
              if(right <=heapSize && A[right].compareTo(A[largest])>0) {
                   largest=right;
              if(largest!=badIndex){
                   Comparable temp=A[badIndex];
                   A[badIndex]=A[largest];
                   A[largest]=temp;
                   maxHeapify (A,largest,badIndex);

    This is my code:
    public class HeapSort {
         //Sorts an array of data of the specified type, using the heap sort algorithm,
         //and returns the number of comparisons made.
         public void heapSort(java.lang.Comparable[] data){
              int n=data.length-1;
              buildMaxHeap(data);
              for(int i=n;i>=2;i--){
                   Comparable temp=data[1];
                   data[1]=data;
                   data[i]=temp;
                   --n;
                   maxHeapify(data,1,n);
         //Sorts the first heapSize elements of array A, using heap sort.
         //Assumes heapSize is less than or equal to A.length.
         public void heapSort(java.lang.Comparable[] A, int heapSize) {
              for(int i=A.length-1;i>1;i--) {
                   Comparable temp=A[1];
                   A[1]= A[i];
                   A[i]=temp;
                   --heapSize;
                   maxHeapify(A,1,heapSize);
         public void buildMaxHeap(java.lang.Comparable[] A){
              int hs=A.length-1;
              for(int i=hs/2;i>1;i--){
                   maxHeapify(A,i,hs);
         public void maxHeapify(java.lang.Comparable[] A, int badIndex, int heapSize){
              int left=2*badIndex;
              int right=2*badIndex+1;
              int largest;
              if(left<=heapSize && A[left].compareTo(A[badIndex]) > 0) {
                   largest=left;
              else {
                   largest=badIndex;
              if(right <=heapSize && A[right].compareTo(A[largest])>0) {
                   largest=right;
              if(largest!=badIndex){
                   Comparable temp=A[badIndex];
                   A[badIndex]=A[largest];
                   A[largest]=temp;
                   maxHeapify (A,largest,badIndex);

  • HELP making me go insane.

    I need a method to sort an array of integers into ascending order.
    I have already done methods to find the smallest and largest
    ie
    public static void maxnumber(int [] name,int arraysize)
    int m =name[0];
    for(int j=0;j<arraysize;j++)
    if(name[j]>m)
    m=name[j];
    System.out.println (m);
    I just need one that puts all the numbers in ascending order and i
    cant figure out the logical sequence for it. help!

    Why don't you use java.util.Arrays.sort(int[] a)? This class is in the Standard Edition since 1.2.
    If you want to implement an own method: there are a lot of books about sorting algorithms: bubble sort, heap sort, and quick sort are the most common algorithms. Please read "Algorithms" by Sedgewick or "Algorithms And Data Structures" by Wirth.
    If you installed the J2SE V1.2 or higher, you might want to read the sources of the class Arrays, which uses a tuned form of the quicksort algorithm.
    HTH

  • Sorting of user list in 'ACT AS' by displayname -OBIEE 11G

    Hi,
    I have configured 'ACT AS' successfuly in obiee 11g . We have written the following query to populate user name and displayname in the act as drop down .
    <getValues>EXECUTE PHYSICAL CONNECTION POOL DAA2.DAA2 select USERNAME, DISPLAYNAME from SIEBEL_USERS </getValues>
    With this query the list is getting ssorted by USERNAME .
    However, our client expects the user list to be populated in the ascending order of the DISPLAYNAME.
    I tried modifying the above query as below in the xml file to implement the same .
    <getValues>EXECUTE PHYSICAL CONNECTION POOL DAA2.DAA2 select USERNAME, DISPLAYNAME from SIEBEL_USERS Order by 2 desc </getValues>
    But the liste is still getting sorted by USERNAME. Could anyone give some pointers to achieve this requirement ?
    Regards,
    Karan
    Edited by: kchadha2 on Sep 12, 2011 7:21 PM

    Thanks Veeravalli, I did exactly the same. Editing the registry didn't help so I deleted the service from registry and create it again and before that added the following in my installSVC file in the section you mentioned
    set JAVA_VM=-server
    set MEM_ARGS==-Xms1024m -Xmx1024m -XX:MaxPermSize=2048m -XX:-UseSSE42Intrinsics
    But it is still not working, I am getting the same error but now it says
    [Tue Dec 11 07:38:45 2012] [RunJavaApp] Loading class - =-Xms1024m
    java.lang.NoClassDefFoundError: =-Xms1024m
    Caused by: java.lang.ClassNotFoundException: =-Xms1024m
         at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    one of the things I didn't mention though was that when I create the service, I run the installAdmServer_Service.cmd file as "Run as Administrator", only then the service gets installed. Can this be related to the fact that this windows service needs to be run under admin account? or Run as Administrator? I am guessing because I tried various heap sizes and also edited my setDomainEnv.cmd and commEnv.cmd file to use 1024 as heap size it but still didn't work and it is failing may be while loading the class? If that is the case then how to run this services as administrator? Am I missing anything else?
    Thanks,
    Ronny

  • When using external-scheme what is still stored on-heap?

    Hi all,
    If I have a scheme like this...
    <distributed-scheme>
        <scheme-name>distributed-scheme</scheme-name>
        <service-name>TestDistributedService</service-name>
        <backing-map-scheme>
          <external-scheme>
            <lh-file-manager>
              <directory>/temp/odc-data</directory>
            </lh-file-manager>
          </external-scheme>
        </backing-map-scheme>
    </distributed-scheme>...when I put data into a cache what is still stored on the heap?
    When I do a test I can see that obviously the data is not on the heap as I can add massively more entries before I run out of memory.
    Using the VisualVM tool's memory sampler I can see a similar number of instances of com.tangosol.util.Binary as I have entries - so are they keys still on the heap?
    If I add indexes then I can see that these are on the heap, so I will have keys and indexed values on the heap. I end up with twice as many instances of Binary as I have put entries, which makes sense as the index contains a references to the Binary keys.
    The reason I ask is because I configured a "Dev" version of our application that uses <external-scheme> everywhere you would normaly use a <local-scheme> so we can run a version of our application for Dev testing on development machines with limited RAM. It needed a few tweaks and a custom DefaultConfigurableCacheFactory but seems to work fine. I am now trying to figure out just how much space we save and how much "data" is still on the heap.
    Cheers,
    JK

    Thanks David.
    So with an external scheme we will be able to save the amount of space taken by the cache values. Now if I could just shift the indexes (which take quite a bit of space) that would be a bonus. I know it sort of defeats the point of having an index but I am trying to run the app on a small Dev server so I am more interested that it works functionally than how fast it is. If the app was 3.6 I might be able to do something clever with custom indexes - then again we could just remove the indexes.
    Cheers,
    JK

  • Importing videos: rename uses correct date but sorted to incorrect date folder

    Hello
    I know there is an issue with importing photos directly from a device, that's not what's happening here.
    I  import photos from my camera's SD card and I rename them as they import.  Photos and video are both renamed correctly, but only the photos are sorted correctly.  The videos seem to sort based on the additional time zone adjustment, so mostly they end up in the folder for the next day (corresponding to an additional +12 hr, as though lightroom was adding the time zone correction to the local time rather than to the GMT time).  In gallery view I need to sort by name in order to sort by capture time because the renaming is the only feature that reads the correct capture time.  Sorting by capture time uses the capture time displayed in the metadata (in the right panel in the library module), which seems unrelated to the capture time.  I think it might have somethign to do with the import time, but it doesn't match any of the properties in windows explorer.
    For example:
    I took a video at 2015-02-07 1509, and that time/date appears in it's name
    It was taken in New Zealand in a +12 hr time zone (so GMT time 2015-02-07 0309, and if we apply the time zone correction to the local time it would be 2015-02-08 0309)
    When is was auto-sorted during the import it ended up in the 2015-02-08 folder
    The lightroom metadata capture time is listed as 2015-02-08 2158
    The windows explorer date modified is 2015-02-08 1509 (the correct capture time)
    The windows explorer date created and date accessed are 2015-02-08 11:27
    Note that the camera has GPS and photos are GPS tagged, so they are linked to the time zone.  As far as I can tell the videos are not GPS tagged (no GPS coordinates in properties in windows explorer).
    I'd like for the metadata to show the correct capture time and for the videos to be sorted by that correct capture time.  Lightroo obviosuly has the ability to read the capture time correctly, because it does so for the naming.  I have no idea what's going on here and would be heaps grateful for help from the wonderful adobe forums community (you guys haven't let me down yet, you beat any customer support line I've ever tried).
    PS: This is the first of a few issues I'm having with lightroom and capture time and  videos, so if you like a challenge stay tuned as I post them all up.  I'm still going through them but briefly:
    - similar video-only issues with videos from another camera: I have to double check to see if the details are the same
    - I'm having time zone issues with screenshots and saved snapchat photos from my iphone even when they are imported from a separate folder
    - accessing the capture time of iphone screenshots/snapchat photos: they get renamed based on a capture time (either the correct or time zone offset, but always something meaningful and not a blank or random time) but lightroom won't display the capture time metadata when looking at only those images, making the time zone adjustment very difficult

    LR's support for video metadata is incomplete and buggy.  Add your vote and opinion to this thread: Lightroom: Metadata applied to videos in Lightroom isn't available in other applications.

  • Sort by Task Status doesn't stay sorted?

    A useful feature is to sort computer lists by task status.... at least it would be a useful feature if it worked, but I find that it 'deorganizes' itself after a second. Oops!
    Does anyone have a solution or should i just pray the bug gets fixed some day? (as usual...)

    I was waiting until this evening to see if restarting the server would fix this.
    And it has.
    All the tasks work perfectly - those failing with both the error codes, so that's my own apps and also the SyncBackup tasks.
    For now...
    Digging around some more, I'm led to believe this might have something to do with "Desktop Heap" size.
    http://blogs.msdn.com/b/ntdebugging/archive/2007/01/04/desktop-heap-overview.aspx
    Thing is, this never used to happen up until very recently on one of my servers, I migrated to a new one (not because of this) mystified by the problem and hoping the problem would vanish. And it did, at first.
    One other server I have which runs SyncBackup tasks doesn't have this issue.
    All Windows Server 2008 R2 and all up to date with hotfixes.
    I'm reluctant to modify the Desktop Heap size without a more detailed understanding and still mystified as to why this all worked perfectly until about three weeks ago.

  • UCCX 7 Heap Memory Usage Exceeded Error

    UCCX 7.0.(1) SR5
    Getting the following error when updating or adding new script applications:
    "It is not recommended to update the application as Engine heap memory usage exceeded configured threshold. Click OK to continue and Cancel to exit."
    Apparently this is an alert that was built into SR4 and is configurable under the System Parameters.
    Does anyone have information on what processes use the heap memory in UCCX or how to monitor the usage?

    As Tom can attest to by now, this is something of an iceberg with big sharp edges below the surface.
    The Java heap is fixed at 256MB on CCX. The Java heap is used by Tomcat as execution memory. In addition to this, applications, scripts, and other repository data is loaded into the heap at runtime. Depending on your environment, you may be approaching the limits of the heap, which cannot be changed. If the heap size is reached, it will be dumped and impact calls.
    What have you been doing as of late on your CCX server? How many applications and scripts do you have? Are any of these using XML files extensively?
    Note there is also a possible bug where the MIVR engine does not properly release all objects loaded into the heap at the end of a script execution leading to a memory leak of sorts. The discussion [debate] over this behavior is continuing. As of this week, it may be represented under
    /* Style Definitions */
    table.MsoNormalTable
    {mso-style-name:"Table Normal";
    mso-tstyle-rowband-size:0;
    mso-tstyle-colband-size:0;
    mso-style-noshow:yes;
    mso-style-priority:99;
    mso-style-parent:"";
    mso-padding-alt:0in 5.4pt 0in 5.4pt;
    mso-para-margin:0in;
    mso-para-margin-bottom:.0001pt;
    mso-pagination:widow-orphan;
    font-size:10.0pt;
    font-family:"Times New Roman","serif";}
    CSCte49231. If it is, this may qualify as the most poorly described defect ever.

  • Crystal Report export to PDF cause high Heap usage ?

    Hi all,
    As part of our reporting integrated with our JSF/JSP application, Crystal report is converted to PDF then sent to browser for user to display. mean while during peak load our Heap usage could reach 3.5GB - 4GB. So I am suspecting the unclosed byteArrayInputStream is the cause.
    (This is a production application so I am collecting information before change the code)
    Is the unclosed() byteArrayInputStream  really cause the problem ?  (the codes is below)
    Thank you,
    Krist
    ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream)
                                     reportClientDoc.getPrintOutputController().export(exportOptions);       
    reportClientDoc.close();
    writeToBrowser(byteArrayInputStream, response, "application/csv", EXPORT_FILE);
    private void writeToBrowser(ByteArrayInputStream byteArrayInputStream, HttpServletResponse
    response, String mimetype, String exportFile)
       throws Exception {
          byte[] buffer = new byte[byteArrayInputStream.available()];
          int bytesRead = 0;
          response.reset();
          response.setHeader("Content-disposition", "inline;filename=" + exportFile);
          response.setContentType(mimetype);
          //Stream the byte array to the client.
          while((bytesRead = byteArrayInputStream.read(buffer)) != -1)
                { response.getOutputStream().write(buffer , 0, bytesRead);}
          //Flush and close the output stream.
          response.getOutputStream().flush();
          response.getOutputStream().close();

    I do not know if my solution to my Heap problem will help any of you but I thought I would just post it here
    just incase yourselves or others come looking for possible solutions.
    I created a very simlpe report with 2 groups and not much in the way of complex functions. Whilst reporting against about
    100 pages of output everything worked fine, but as soon as we pushed the report up to 500+ pages we got all sorts
    of issues.
    java.lang.OutOfMemoryError: Java heap space
    After much hair pulling and trial and error I discovered that the issue came about where I did not declare formula variables as local. I was concatinating various street address details for of the envelope windows.
    Stringvar Address;      //    I was using this declaration
    Global Stringvar Address;    // Specific Global declaration
    Local Stringvar Address;    // Changed to this declaration
    After changing to Local, my report now runs with no hassels. And the memory usage whilst exporting the report has gone from maxing out at over 1GB to almost nothing (dont even get it registering)
    Am sure someone can come up with a better explanation for this and give reasons but just thougth I would share.
    Cheers
    Darren

  • Sorting with TreeMap vs. quicksort

    I've been sorting lists by throwing them into a TreeMap then retrieving them in order (especially for fairly evenly distributed lists of strings), thereby leveraging its binary tree characteristics.
    My belief is that sorting this way takes N log N time, just as quicksort (as in Arrays.sort) does -- because adding items to a TreeMap takes log N time -- without any danger of stack overflows from recursing on a huge list as with quicksort, and fewer method calls which can get expensive.
    I'm figuring that even if this way of sorting uses more memory than an in-place sort as in Arrays.sort, at least it won't overflow the stack, and will mostly be eligible for garbage collection anyway.
    Could someone correct or confirm my conclusions, reasoning or assumptions? And how well do they apply to Collections.sort's merge sort?

    Using a tree guarentees worst case O(n log n) for n
    inserts.Amazing, my untrained intuition was correct.
    As for stack problems these are unlikely to occur until
    logn is at least a few thousand (think about stupidly large values of
    n).I regularly need to sort lists of tends of thousands of strings.
    .. its [quicksort's] gotcha is that
    performance can degrade well below this approaching
    O(n^2) (might be higher. I cant remember).Yes, O(n^2) for adversarial data. Does mergesort require a shallower recursion than quicksort does?
    Since temporary use of the heap is rarely a concern for me, and datasets are very large, it sounds like mergesort and the TreeMap are viable contenders for preferred sorting methods. But I'm still apprehensive about mergesort's use of recursion.
    Thank you, I gave you 5 duke dollars and matei 2.

  • IBook G4 slowdown with find and sort

    My wife's iBook frequently decides to slow down to a mere crawl, and it sounds like the hard drive (I think) is working steadily during these spells. Looking at the processes w/ top, find seems to be sucking up heaps of CPU time. I tried killing the find process, at which point sort and then makewhatis took over and continued beating on the machine. Any idea where these commands are issuing from and how to avoid them or at least reschedule them? (This often happens in the middle of the work day.) Perhaps this is a spotlight issue, since it started around the time we updated to 10.4. But I've noticed no such issues with my powerbook since updating to 10.4.
    Thanks for any suggestions.
    iBook G4   Mac OS X (10.4.4)  

    Errr...  A quick reality check is called for. If you make files visible to the finder then they are no longer invisible files, so ignoring invisible files won't help you one bit. your best bet is to do a manual check for a file that starts with a "." (which would normally be invisible):
    tell application "Finder"
              set thisFolder to folder "Pictures" of home
              set sortedFiles to (sort (files of thisFolder) by modification date) as alias list
              set newestFile to last item of sortedFiles
              if name of newestFile starts with "." then
                        set newestFile to item -2 of sortedFiles
              end if
    end tell

Maybe you are looking for