heap

Heapify in logarithmic time using the C++ standard library

半世苍凉 提交于 2020-01-29 16:59:11
问题 I have a heap using std::make_heap : std::vector<int> v{1,2,3,5,9,20,3}; std::make_heap(v.begin(), v.end()); now I update the heap by changing one random element: v[3] = 35; Is there a way in standard library in to adjust heap again in O(log n) time where n is size of container. Basically I am looking for heapify function. I know what element has been changed. I understand that std::make_heap is O(n log n) time. I have also gone through duplicate question but that is different in sense that

Heapify in logarithmic time using the C++ standard library

寵の児 提交于 2020-01-29 16:58:48
问题 I have a heap using std::make_heap : std::vector<int> v{1,2,3,5,9,20,3}; std::make_heap(v.begin(), v.end()); now I update the heap by changing one random element: v[3] = 35; Is there a way in standard library in to adjust heap again in O(log n) time where n is size of container. Basically I am looking for heapify function. I know what element has been changed. I understand that std::make_heap is O(n log n) time. I have also gone through duplicate question but that is different in sense that

What's the most efficient way to write large text file in java?

不想你离开。 提交于 2020-01-25 06:55:07
问题 I'm trying to write a file with some amount of data using this: public static <T extends SomeClass> void writeFile(String buffer, Class<T> clazz, int fileNumber) { String fileType = ".txt"; File file = new File(clazz.getName()+fileNumber+fileType); PrintWriter printWriter = null; try { FileWriter writer = new FileWriter(file); printWriter = new PrintWriter(writer); printWriter.print(buffer);//error occurs here printWriter.flush(); printWriter.close(); System.out.println("created file: "+file

How is the order of items managed by Python's heapq library determined?

…衆ロ難τιáo~ 提交于 2020-01-23 19:46:48
问题 I was under the impression that the first value was what determined a values position in the heap, however that doesn't seem to be the case. from __future__ import print_function import heapq q = [] heapq.heappush(q, (10, 11)) heapq.heappush(q, (11, 12)) heapq.heappush(q, (9, 10)) print(q) This gives me an output of [(9, 10), (11, 12), (10, 11)] However I was expecting an output like [(9, 10), (10, 11), (11, 12)] 回答1: The condition on heapq is not a "sort guarantee" over the provided list.

How is the order of items managed by Python's heapq library determined?

半腔热情 提交于 2020-01-23 19:46:29
问题 I was under the impression that the first value was what determined a values position in the heap, however that doesn't seem to be the case. from __future__ import print_function import heapq q = [] heapq.heappush(q, (10, 11)) heapq.heappush(q, (11, 12)) heapq.heappush(q, (9, 10)) print(q) This gives me an output of [(9, 10), (11, 12), (10, 11)] However I was expecting an output like [(9, 10), (10, 11), (11, 12)] 回答1: The condition on heapq is not a "sort guarantee" over the provided list.

How to analyze Heap Dumps

那年仲夏 提交于 2020-01-23 15:01:46
问题 I am successful in generating Heap Dumps of my application machine but I do not know how to analyze it. Can someone tell me how to? 回答1: Use jhat utility for Java on Sun solaris. A good example is here https://blogs.oracle.com/alanb/entry/heap_dumps_are_back_with 回答2: You can try VisialVM, for some reason my heap dump wasn't loading in jhat but was in visualVM. It give you a graph of the class that are taking much of the heap. here where to get it: http://visualvm.java.net/download.html 来源:

How to analyze Heap Dumps

陌路散爱 提交于 2020-01-23 14:59:05
问题 I am successful in generating Heap Dumps of my application machine but I do not know how to analyze it. Can someone tell me how to? 回答1: Use jhat utility for Java on Sun solaris. A good example is here https://blogs.oracle.com/alanb/entry/heap_dumps_are_back_with 回答2: You can try VisialVM, for some reason my heap dump wasn't loading in jhat but was in visualVM. It give you a graph of the class that are taking much of the heap. here where to get it: http://visualvm.java.net/download.html 来源:

How to moniter memory allocated by some java method at runtime

跟風遠走 提交于 2020-01-23 11:00:30
问题 I am creating a java program in which my class suppose A has it's some predefined behavior. But user can over-ride my class to change its behavior. So my script will check if there is some subclass than I will call it's behavior but what if he has written some blocking code or memory leak in his code. This may harm my process. Is there is any way in java to monitor memory allocated by some method. Please suggest. 回答1: but what if he has written some blocking code or memory leek in his code

How to moniter memory allocated by some java method at runtime

一笑奈何 提交于 2020-01-23 10:59:30
问题 I am creating a java program in which my class suppose A has it's some predefined behavior. But user can over-ride my class to change its behavior. So my script will check if there is some subclass than I will call it's behavior but what if he has written some blocking code or memory leak in his code. This may harm my process. Is there is any way in java to monitor memory allocated by some method. Please suggest. 回答1: but what if he has written some blocking code or memory leek in his code

Disabling Local JMX Connections on JVM

戏子无情 提交于 2020-01-22 18:50:33
问题 We are writing a java program which keeps a password in memory. Unfortunately, the user can easily use jconsole or jmap to create a heap dump file and open it to find the password. I think jconsole connects jvm using local sockets. I wanna know, is there any way to disable jmx even for local users? Is there any way to totally disable heap dumps? As the user have access to the memory segment, this is possible to access the password anyway. However, I wanna disable standards ways of doing that