How to make sorting in hash table efficient
Hi guys,
I am relatively new to collections.
I have a HashTable which has 100000 records in it, when I sort it, it takes a lot of time to get it done.
As the Hashtable methods are synchronised so even I can't use threads to perform this quickely for me.
Can any one provide any solution using multi threading or any other method to achieve the optimization in
sorting the hashtable.
Thanks,
Atul
As already suggested, use TreeMap if you want to build your table in sorted key order. Otherwise, if you want to sort after the fact, you could do one of the following:
SortedSet sortedKeys = new TreeSet(map.keySet());
// or
List sortedKeys = new TreeSet(map.keySet());
Collections.sort(sortedKeys);Note that this will NOT affect that order in the map. It only affects the order of the extracted keys.
Also not that if sorting 100,000 items is taking "a long time," then you probably wrote your own sort algorithm and it's probably O(n^2) or something.
Similar Messages
-
Hi my name is vishal
For past 10 days i have been breaking my head on how to make column headers in table appear bold while datas in table appear regular from c# windows forms with sql server2008 using iTextSharp.
Given below is my code in c# on how i export datas from different tables in sql server to PDF report using iTextSharp:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Diagnostics;
using System.IO;
namespace DRRS_CSharp
public partial class frmPDF : Form
public frmPDF()
InitializeComponent();
private void button1_Click(object sender, EventArgs e)
Document doc = new Document(PageSize.A4.Rotate());
var writer = PdfWriter.GetInstance(doc, new FileStream("AssignedDialyzer.pdf", FileMode.Create));
doc.SetMargins(50, 50, 50, 50);
doc.SetPageSize(new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.LETTER.Width, iTextSharp.text.PageSize.LETTER.Height));
doc.Open();
PdfPTable table = new PdfPTable(6);
table.TotalWidth =530f;
table.LockedWidth = true;
PdfPCell cell = new PdfPCell(new Phrase("Institute/Hospital:AIIMS,NEW DELHI", FontFactory.GetFont("Arial", 14, iTextSharp.text.Font.BOLD, BaseColor.BLACK)));
cell.Colspan = 6;
cell.HorizontalAlignment = 0;
table.AddCell(cell);
Paragraph para=new Paragraph("DCS Clinical Record-Assigned Dialyzer",FontFactory.GetFont("Arial",16,iTextSharp.text.Font.BOLD,BaseColor.BLACK));
para.Alignment = Element.ALIGN_CENTER;
iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance("logo5.png");
png.ScaleToFit(105f, 105f);
png.Alignment = Element.ALIGN_RIGHT;
SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
SqlCommand cmd = new SqlCommand("Select d.dialyserID,r.errorCode,r.dialysis_date,pn.patient_first_name,pn.patient_last_name,d.manufacturer,d.dialyzer_size,r.start_date,r.end_date,d.packed_volume,r.bundle_vol,r.disinfectant,t.Technician_first_name,t.Technician_last_name from dialyser d,patient_name pn,reprocessor r,Techniciandetail t where pn.patient_id=d.patient_id and r.dialyzer_id=d.dialyserID and t.technician_id=r.technician_id and d.deleted_status=0 and d.closed_status=0 and pn.status=1 and r.errorCode<106 and r.reprocessor_id in (Select max(reprocessor_id) from reprocessor where dialyzer_id=d.dialyserID) order by pn.patient_first_name,pn.patient_last_name", conn);
conn.Open();
SqlDataReader dr;
dr = cmd.ExecuteReader();
table.AddCell("Reprocessing Date");
table.AddCell("Patient Name");
table.AddCell("Dialyzer(Manufacturer,Size)");
table.AddCell("No.of Reuse");
table.AddCell("Verification");
table.AddCell("DialyzerID");
while (dr.Read())
table.AddCell(dr[2].ToString());
table.AddCell(dr[3].ToString() +"_"+ dr[4].ToString());
table.AddCell(dr[5].ToString() + "-" + dr[6].ToString());
table.AddCell("@count".ToString());
table.AddCell(dr[12].ToString() + "-" + dr[13].ToString());
table.AddCell(dr[0].ToString());
dr.Close();
table.SpacingBefore = 15f;
doc.Add(para);
doc.Add(png);
doc.Add(table);
doc.Close();
System.Diagnostics.Process.Start("AssignedDialyzer.pdf");
if (MessageBox.Show("Do you want to save changes to AssignedDialyzer.pdf before closing?", "DRRS", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation) == DialogResult.Yes)
var writer2 = PdfWriter.GetInstance(doc, new FileStream("AssignedDialyzer.pdf", FileMode.Create));
else if (MessageBox.Show("Do you want to save changes to AssignedDialyzer.pdf before closing?", "DRRS", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation) == DialogResult.No)
this.Close();
The above code executes well with no problem at all!
As you can see the file to which i create and save and open my pdf report is
AssignedDialyzer.pdf.
The column headers of table in pdf report from c# windows forms using iTextSharp are
"Reprocessing Date","Patient Name","Dialyzer(Manufacturer,Size)","No.of Reuse","Verification" and
"DialyzerID".
However the problem i am facing is after execution and opening of document is my
column headers in table in pdf report from
c# and datas in it all appear in bold.
I have browsed through net regarding to solve this problem but with no success.
What i want is my pdf report from c# should be similar to following format which i was able to accomplish in vb6,adodb with MS access using iTextSharp.:
Given below is report which i have achieved from vb6,adodb with MS access using iTextSharp
I know that there has to be another way to solve my problem.I have browsed many articles in net regarding exporting sql datas to above format but with no success!
Is there is any another way to solve to my problem on exporting sql datas from c# windows forms using iTextSharp to above format given in the picture/image above?!
If so Then Can anyone tell me what modifications must i do in my c# code given above so that my pdf report from c# windows forms using iTextSharp will look similar to image/picture(pdf report) which i was able to accomplish from
vb6,adodb with ms access using iTextSharp?
I have approached Sound Forge.Net for help but with no success.
I hope anyone/someone truly understands what i am trying to ask!
I know i have to do lot of modifications in my c# code to achieve this level of perfection but i dont know how to do it.
Can anyone help me please! Any help/guidance in solving this problem would be greatly appreciated.
I hope i get a reply in terms of solving this problem.
vishalHi,
About iTextSharp component issue , I think this case is off-topic in here.
I suggest you consulting to compenent provider.
http://sourceforge.net/projects/itextsharp/
Regards,
Marvin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
URGENT can anyone let me know how to include sort buttons in table maintian
hi
can anyone let me know how to include sort buttons in table maintianence
as generally table maintianec done have sort buttons i need to include the sort buttons kindly let me know on that asap
or can we use module pool in between table maintianece screen
if yes how touse and how to cod for that
regards
AroraYou can change the coding of Table Maintenance.
>> Goto SM30, give table name and goto Display/Maintain mode and copy all the GUI status from standard program into your function group. Add sort button in the GUI Status of Maintain & Display mode.
>> Goto to tablemaintenance screen generated using SE51.
>> Select change mode.
>> After PROCESS BEFORE OUTPUT, create one module to assign your function group program name to " X_HEADER-GUI_PROG = "
>> In PROCESS AFTER INPUT, add another module at the end to perform the action.
-Alpesh.Saparia -
How to make a column in Table popin read only
Hi Everyone
Could anyone let me know how to make a column in table popin read only.
Regardsif you ar eusing an ALV table
try this
DATA: lr_salv_wd_table TYPE REF TO iwci_salv_wd_table,
r_table TYPE REF TO CL_SALV_WD_CONFIG_TABLE.
* get reference to ALV component interface
lr_salv_wd_table = wd_this->wd_cpifc_alvmain( ).
* get ConfigurationModel from ALV Component
wd_this->r_table = lr_salv_wd_table->get_model( ).
* init ColumnSettings
DATA: lr_column_settings TYPE REF TO if_salv_wd_column_settings,
lr_col_header TYPE REF TO cl_salv_wd_column_header.
lr_column_settings ?= wd_this->r_table.
* get table of column settings - each line one column
DATA: lt_columns TYPE salv_wd_t_column_ref.
lt_columns = lr_column_settings->get_columns( ).
* loop over table - in each loop another column can be modified
DATA: ls_column TYPE salv_wd_s_column_ref.
* define visible columns (fields) by naming them,
* exclude others by setting visibility to none
DATA: ls_tooltip TYPE string.
LOOP AT lt_columns INTO ls_column.
" get header of column
lr_col_header = ls_column-r_column->get_header( ).
" do settings here
ENDLOOP.
Or see this document for more tips.
<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/40794172-b95a-2910-fb98-b86d8a0918b4">https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/40794172-b95a-2910-fb98-b86d8a0918b4</a>
regards,
Joris -
How to make records to the table TRFCQIN
hi all,
anyone can tell me
how to make records to the table TRFCQIN
regardsHi Wanna,
Write a module pool program to enter record into table TRFCQIN.
Take fields to which u want to make entries in module pool.
Use insert command to append data in table TRFCQIN.
Refer this code :
CASE OK_CODE_101.
WHEN 'SAV1'.
TRFCQIN-QNAME = 'XYZ'.
TRFCQIN-QCOUNT = "Screen field name at which user will enter value
INSERT TRFCQIN.
if sy-subrc <> 0.
message e007.
else.
clear TRFCQIN.
clear ok_code_101.
endif.
endcase.
Reward points if helpful.
Regards,
Heamnt -
What is the difference between standard,sorted and hash table
<b>can anyone say what is the difference between standard,sorted and hash tabl</b>
Hi,
Standard Tables:
Standard tables have a linear index. You can access them using either the index or the key. If you use the key, the response time is in linear relationship to the number of table entries. The key of a standard table is always non-unique, and you may not include any specification for the uniqueness in the table definition.
This table type is particularly appropriate if you want to address individual table entries using the index. This is the quickest way to access table entries. To fill a standard table, append lines using the (APPEND) statement. You should read, modify and delete lines by referring to the index (INDEX option with the relevant ABAP command). The response time for accessing a standard table is in linear relation to the number of table entries. If you need to use key access, standard tables are appropriate if you can fill and process the table in separate steps. For example, you can fill a standard table by appending records and then sort it. If you then use key access with the binary search option (BINARY), the response time is in logarithmic relation to
the number of table entries.
Sorted Tables:
Sorted tables are always saved correctly sorted by key. They also have a linear key, and, like standard tables, you can access them using either the table index or the key. When you use the key, the response time is in logarithmic relationship to the number of table entries, since the system uses a binary search. The key of a sorted table can be either unique, or non-unique, and you must specify either UNIQUE or NON-UNIQUE in the table definition. Standard tables and sorted tables both belong to the generic group index tables.
This table type is particularly suitable if you want the table to be sorted while you are still adding entries to it. You fill the table using the (INSERT) statement, according to the sort sequence defined in the table key. Table entries that do not fit are recognised before they are inserted. The response time for access using the key is in logarithmic relation to the number of
table entries, since the system automatically uses a binary search. Sorted tables are appropriate for partially sequential processing in a LOOP, as long as the WHERE condition contains the beginning of the table key.
Hashed Tables:
Hashes tables have no internal linear index. You can only access hashed tables by specifying the key. The response time is constant, regardless of the number of table entries, since the search uses a hash algorithm. The key of a hashed table must be unique, and you must specify UNIQUE in the table definition.
This table type is particularly suitable if you want mainly to use key access for table entries. You cannot access hashed tables using the index. When you use key access, the response time remains constant, regardless of the number of table entries. As with database tables, the key of a hashed table is always unique. Hashed tables are therefore a useful way of constructing and
using internal tables that are similar to database tables.
Regards,
Ferry Lianto -
what happens when duplicate entries are present in sorted and hashed tables?
Hi,
Sorted internal tables can be of two types:
unique or non unique.
If u enter duplicate records in Sorted tables with unique it will show error.
If u enter duplicate records in Sorted tables with non-unique key it will not show error.
Hashed tables are with only unique key
so no way to enter the duplicate records.
for more information see the following link
http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb35de358411d1829f0000e829fbfe/content.htm
Reward if helpful.
Jagadish -
Hash Table efficiency question
Hi experts,
In my program, I want to read in a lot of string and store the occurance of each string. I found that hash table is the best and most efficient option, but the problem is that, hash table only store one item.
So, I either have to:
1) store an array object into each hash table entries. ie String[String][Occurance]
2) create two hash table based on the hash code of the string.
For 2) I am planning to store all distinct String into one hashtable using the string as the hashcode, then create another hashtable to store the occurance using the String as the hashcode.
My question is that:
1)which implementation is more efficient? Constantly creating String array for each entry or create two hashtables?
2) Is the second implementation possible? Would the hashcode be mapped to different cell in the hashtable even the two hashtable are using the same hashcode and the same size?
Thank you very much for your help.
KevinI am wondering what it is you are trying to do, but I am assuming you are trying to find the number of occurrences for a particular word, and then determining which word has the highest value or the lowest value? You can retrieve the initial String value by using the keys() method of the hashtable. You can use it to traverse the entire table and compare the counts there.
If you really wanna store another reference for that string, create a simple object
public final class WordCount {
* The Word being counted.
* @since 1.1
private String _word;
* Count for the Number of Words.
* @since 1.1
private int _count;
* Creates a new instance of the Word Count Object.
* @param word The Word being counted.
* @since 1.1
public WordCount(final String word) {
super();
_word = word;
_count = 0;
* Call this method to increment the Count for the Word.
* @since 1.1
public void increment() {
_count++;
* Retrieves the word being counted.
* @return Word being counted.
* @since 1.1
public String getWord() {
return _word;
* Return the Count for the Word.
* @return Non-negative count for the Word.
* @since 1.1
public int getCount() {
return _count;
}Then your method can be as follows
* Counts the Number of Occurrences of Words within the String
* @param someString The String to be counted for
* @param pattern Pattern to be used to split the String
* @since 1.1
public static final WordCount[] countWords(final String someString, final String pattern) {
StringTokenizer st = new StringTokenizer(someString, pattern);
HashMap wordCountMap = new HashMap();
while (st.hasMoreTokens()) {
String token = st.nextToken();
if (wordCountMap.containsKey(token)) {
((WordCount) wordCountMap.get(token)).increment();
} else {
WordCount count = new WordCount(token);
count.increment();
wordCountMap.put(token, count);
Collection values = wordCountMap.values();
return (WordCount[]) values.toArray(new WordCount[values.size()]);
}Now you can create your own comparator classes to sort the entire array of Word Count Objects. I hope that helps
Regards
Jega -
How to get values from Hash Table
Hi all,
I have a hash table "lovResults" craeted with following code -
String lovInputSourceId = pageContext.getParameter(SOURCE_PARAM);
Hashtable lovResults = pageContext.getLovResultsFromSession(lovInputSourceId);
values which I can see through SOP are - ******Value of lovResults is{roleid=1000, domainFV=CREATIVE, Role=Account Director}
How can I get the domain value "domainFV=CREATIVE" from hash table in a variable because I have to set this vaue in another field.
Please help me ASAP
Thanks
AmitHi Amit ,
Since you are successfully printing the values using sop's , please try this code
Capture the value in controller .
if(oapagecontext.getParameter("domainFV") != null)
String formvalue= oapagecontext.getParameter("domainFV") // ensure hashtable id is correct
Keerthi
Edited by: keerthioaf on Nov 26, 2012 8:46 PM -
How to make data in a table availabel for copying?
I'm trying to display a result set in a table, so that they could be copy-pasted to another file (be that a text file, an Excel spreadsheet or anything). The table comes out okay. But, as I try to copy the data, nothing is copied. So, I want to know how to make the data in the table available for copying. Thanks!
This is exactly what I'm trying to do. The problem is that the data just doesn't get to the clipboard. No matter how hard I try clicking Ctrl-C, it's just not there. When I press Ctrl-V it's not pasted. Why? And how can I correct this problem? Maybe there is some property in JTable class that I have to set as 'true'?
-
HOW TO MAKE THE FIELDS ON TABLE CONTROL SCREEN FIXED!!
Dear all,
Can you please tell me as to how to make the fields on the table control screen fixed (not respond to the scroll bar) i.e. simillar to MC88 screen , the first two fields are fixed and don't respond to the scroll.
Please Help!!!!
VjHi
In TC, goto attributes and set 'Fixed columns' as 2. This will fix the first 2 columns.
Regards
Navneet -
How to make entry in a table e.g. vbak table
how make entries in a table.
what is the procedure.
can i do it in production directly?>
Vijay Babu Dudla wrote:
> it is not possible to do it directly in production. if you do that you will loose your job, don't practice those on production.
More than loosing you job you are violating the contractual terms with SAP. You will simply loose all Support from SAP.
I wonder how an ABAPer got a uid in Proction Server. Its a strict no-no in our organization.
pk -
How to make two matrix and table into same group in SSRS
Hi
i need to dispaly to dispaly data matrix and table . but matrix data on first page and table data on second page.
how to achive this . if i give pagebreak for every new instance for matrix, only matrix data is getting dispalyed in one page and on the second page seocond record date is getting displayed. after all matrix data is displayed ( in separate pages) , table
data is being dispalyed.
but i want to display matrix data on first page and table data on the second page for the first record. for second record also it should display matrix data on 3rd page and table data on 4th page etc..
i mean how to make matrix and table data as same group. so that i can set "page break for new instamce" etc..
how to achive this in SSRS2008Hi Ramkanuganti,
From your description, you want to group both the matrix and table on the same field and add a page break between the two controls for each instance at run time.
To achieve your goal, we can display the matrix in a list and display the table in a nesting list. Please refer to the steps below:
Drag a “List” to the design surface. Drag the matrix into the top of the list (list1).
Drag a “”List” to the list1, under the matrix. Drag the table into the nesting list (list2).
Select “list1” and open the “Group Properties” from the “Row Groups” pane. Add the field on which you want to group the data. In the “Page Breaks” tab, select the “Between each instance of a group”.
Repeat step 3 to configure the “list2” using the same field. Additionally, please also select the “Also at the start of a group” option.
For more information about how to work with list, please refer to:
Adding a List
If you have any further questions, please feel free to ask.
Regards,
Mike Yin -
How do you sort the entire table in numbers with OSX Maverick?
Before the upgrade of Numbers 3.0 & Maverick, you use to sort the enire table by (1) Highlighting the entire table, (2) using the drop down arrow in the columns, (3) select the option to set your sort requirements.
Now, I am not able to find a way to do this.
Please help!Frederick -
Thanks for the idea, however, I'm trying to Reoganize my entire table. I'm afraid it is a very convient function that has been removed.
Sad to think that the ones designing these programs, don't actually use them.
~K~ -
How to Implement a Chained Hash Table with Linked Lists
I'm making a migration from C/C++ to Java, and my task is to implement a Chained Hash Table with a Linked List. My problem is to put the strings(in this case names) hashed by the table using de Division Metod (H(k)= k mod N) in to a Linked list that is handling the colisions. My table has an interface implemented(public boolean insert(), public boolean findItem(), public void remove()). Any Help is needed. Thanks for everyone in advance.
OK. you have your hash table. What you want it to do is keep key/value pairs in linked lists, so that when there is a collision, you add the key/value pair to the linked list rather than searching for free space on the table.
This means that whenever you add an item, you hash it out, check to see if there is already a linked list and if not, create one and put it in that slot. Then in either case you add the key/value pair to the linked list if the key is not already on the linked list. If it is there you have to decide whether your requirements are to give an error or allow duplicate keys or just keep or modify one or the other (old/new).
When you are searching for a key, you hash it out once again and check to see if there is a linked list at that slot. If there is one, look for the key and if it's there, return it and if not, or if there was no linked list at that slot, return an error.
You aren't clear on whether you can simply use the provided linked-list implementations in the Java Collections or whether you have to cobble the linked list yourself. In any case, it's up to you.
Is this what you're asking?
Doug
Maybe you are looking for
-
How to connect a printer to Airport in WIFI with Windows
Hi, I just would like to know how to connect my printer (Samsung) to my Airport network through WIFI (My computer is working with Windows). Thanks
-
B-Day set up in Address book shows up in iCal but won't sync to iPhone
And it would be my Mothers! I don't sync over air. Always sync through iTunes,, and I have marked "all iCalendars to sync".. I have 3 calendars plus a Birthday's one. I also have a "Birthdays Calendar". After I sync, all the Birthdays EXCEPT this par
-
Problem downloading netweaver trial version
hi, I'd like to download the trialversion 7.01, but the download always stops after a few seconds and then I get the message "sapnw7.0rar.part could not be safed because source could not be read. try again later or contact the administrator" can anyo
-
Hi, I have a requirement like three dropdown boxes 1)Select a country based on that populate 2)Currency and based on that populate 3)Price List after populatiing data in three dropdown boxes I have some Tabedpanels on the same page like PriceList,Sal
-
Re:reports(technical name)
Morning gurus I am running some reports in bex analyzer how can i know the technical name of any report query and how can i find whether it is a sap standard one or z report thanks pv