Fastest Way To Find String In Map?

problem: basically im trying to match the value of one Map with the key of another. my thinking is that this requires me to loop through the first Map and for each value through the second Map and match up the key to it. heres my code so far:
private static Map equiJoin(Map relation1, Map relation2) // The 2 maps
Map resultRelation = new TreeMap();
Iterator keys1Iterator = relation1.keySet().iterator();
Iterator values1Iterator = relation1.values().iterator();
while (keys1Iterator.hasNext() ) // Loop through relation1
String primaryKey1 = (String) keys1Iterator.next();
String foreignKey1 = (String) values1Iterator.next();
List list = new ArrayList();
Iterator keys2Iterator = relation2.keySet().iterator();
Iterator values2Iterator = relation2.values().iterator();
while (keys2Iterator.hasNext() ) // Loop through relation2
String primaryKey2 = (String) keys2Iterator.next();
String foreignKey2 = (String) values2Iterator.next();
if(primaryKey2.equals(foreignKey1))
list.add(foreignKey1);
list.add(foreignKey2);
resultRelation.put(primaryKey1, list);
return resultRelation;
im trying to come up with ways to make this faster, perhaps by turing the second while loop/linear search into a binary search.
any thoughts would be appreciated.

problem: basically im trying to match the value of one
Map with the key of another. my thinking is that this
requires me to loop through the first Map and for each
value through the second Map and match up the key to
it. heres my code so far:
private static Map equiJoin(Map relation1, Map
relation2) // The 2 maps
Map resultRelation = new TreeMap();
Iterator keys1Iterator =
relation1.keySet().iterator();
Iterator values1Iterator =
relation1.values().iterator();
while (keys1Iterator.hasNext() ) // Loop through
relation1
String primaryKey1 = (String) keys1Iterator.next();
String foreignKey1 = (String) values1Iterator.next();
List list = new ArrayList();
Iterator keys2Iterator =
relation2.keySet().iterator();
Iterator values2Iterator =
relation2.values().iterator();
while (keys2Iterator.hasNext() ) // Loop through
relation2
String primaryKey2 = (String) keys2Iterator.next();
String foreignKey2 = (String) values2Iterator.next();
if(primaryKey2.equals(foreignKey1))
list.add(foreignKey1);
list.add(foreignKey2);
resultRelation.put(primaryKey1, list);
return resultRelation;
im trying to come up with ways to make this faster,
perhaps by turing the second while loop/linear search
into a binary search.
any thoughts would be appreciated.Yep. The inner loop is not needed. Just use Map api.
Object value2 = relation2.get(primaryKey1);
// and check for null for value2, if null don't add to the list, if not null, do a resultRelation.put
btw, you list add logic:
if(primaryKey2.equals(foreignKey1))
list.add(foreignKey1);
list.add(foreignKey2);
resultRelation.put(primaryKey1, list);
} why do you add both foreignKey1 and foreignKey2 to the list when they are equals. Since they are equals, are they redundent?
--lichu                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Fastest way to find parents with only one child?

    I have two very large tables (both >6 million rows) in an oracle 8i DB. They have a parent child relationship and I would like to construct a query to give me the parents that have only one child......syntactically, what's the best way to construct this query?
    I was going to try:
    select join_id
    FROM parent
    where join_id in (select join_id, count(join_id)
    FROM child
    group by join_id
    having count(*)=1)
    but then I realized that the subselect has two columns to return and the primary query is only expecting one column, so this will not work.
    I suspect there's a quick and dirty way to find out what parents have only one child....
    I thought of using rowid's but am not sure this is the best way and in the example below I tried, I'm having problems b/c of functions not being allowed in the where clause.....
    select join_id
    from child d
    where rowid in (select min(rowid)
              FROM child s
              WHERE min(d.rowid)=max(s.rowid)
              AND s.join_id=d.join_id))
    Any thoughts?

    The two tables are order_header and order_detail. The order_header carries order specific information and the detail contains item specific information.
    So if you had ordered three separate products, you would have:
    one row in the order_header table (parent)
    and three rows in the order_detail table (child)
    They are linked by order_number.
    I presented the problem this way to make it more accessible to more posters.....;)
    One possible solution that I've thought of for my problem is this:
    select join_id
    from child_table d
    where (d.rowid, d.rowid) IN (select min(rowid) MIN_ROW
                   ,max(rowid) MAX_ROW
                   FROM child_table
                   WHERE s.str_order_number=d.str_order_number
                   AND s.date>='30-JAN-2005'
                   AND s.date<='31-JAN-2005'))
    I think this might work because I think that we can safely assume that if the minimum rowid and the maximum rowid (with the same join_id ) are the same then there is only one child record.....is this logic correct?

  • What is the fastest way to find a Node in an xml ?

    Hi all,
    We have a procedure which has to process huge XML documents (files of up to 250Mega).
    Without going too deep in the algorithm, I need to read data from legacy and build nodes in XML.
    In the legacy data I have written in tabular form the xml hierarchy
    For example Root-Branch1-SubBranch2-Leaf1
    I need the fastest possible algorithm to point to SubBranch2, so that I can append Leaf1 Node, in the example.
    Can anybody suggest me the right approach ? for example I wonder if I can use together SAX for finding the parent node and DOM for appending new Nodes ? or can I use XPath ?
    Any suggestion is really welcome!
    Thanks
    Francesco

    Not sure if XPath is built on top of DOM or SAX in most implementations, but that would be a major decider. If DOM, you cannot possible hope to ready that many megabytes into memory on a consistent basis (especially if your system is handling other requests). If SAX, then memory should not be as much of an issue and may be a viable option.
    However, if you are only descending two or three levels into the hierarchy of a document, XPath would really only be a 'convenience' feature. It would be trivial for you to write your own SAX parser to descend to this level. At the same time, you would have a custom XML serializer (just outputing the strings read in from SAX) that would append additional markup according to your requirements.
    Due to the size of your document, memory could be an issue. This will tend to make you gravitate towards SAX.
    - Saish

  • PowerShell - what is the most efficient/fastest way to find an object in an arraylist

    Hi
    I Work with a lot of array lists in PowerShell when working as a sharepoint administrator. I first used arrays but found them slow and jumped over to array lists.
    Often i want to find a specific object in the array list, but the respons-time varies a lot. Does anyone have code for doing this the most efficient way?
    Hope for some answers:-)
    brgs
    Bjorn

    Often i want to find a specific object in the array list, but the respons-time varies a lot. Does anyone have code for doing this the most efficient way?
    As you decided to use an ArrayList, you must keep your collection sorted, and then use the method BinarySearch() to find the objects your looking for.
    Consider using a dictionary, and if your objects are string type, then a StringDictionary.
    You stil fail to understand that he slowness is no in the arraylist.  It is in the creating of the arraylist which is completely unnecessary.  Set up a SharePoint servefr and create a very large list and test..  You will see. An arraylist
    with 10000 items takes forever to create. A simple SharePoint search can be done in a few milliseconds.
    Once created the lookup in any collection is dependent on the structure of the key and the type of collection.  A string key can be slow if it is a long key.
    The same rules apply to general database searches against an index.
    The main point here is that SharePoint IS a database and searching it as a database is the fastesst method.
    Prove me wrong devil!    Submit!  Back to your cage! Fie on thee!
    ¯\_(ツ)_/¯
    You seem to be making a lot of assumptions about what he's doing with those arraylists that doesn't seem justified based on no more information than there is in the posted question.
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • Fastest way to find duplicates

    10.2.0.5
    I would be intersted if anything was added in 11g.
    I have a 148 gb table that is not partitioned and does not have a unique index. I am not allowed to add an index to see if there are duplicates (I know how to do this to get the row ids).
    Group by generates too much temp even if I increase hash and sort area size.
    I can try parallel, but this does not seem to help much if the table is not partitioned.
    Is there anythign better than select count(distinct fiields).
    Is an analytic better?
    anything new in 11g that is better?

    What I used to do when I had more data than Oracle could handle was something like this in korn shell:
    echo '
    username/password
    set linesize 200
    set pages 0
    set heading off
    set termout off
    set verify off
    set echo off
    set feedback off
    -- any other sets needed
    select * from bigtable
    /'|sqlplus -s|grep -v ^$|sort > j$$1
    echo '
    username/password
    set linesize 200
    set pages 0
    set heading off
    set termout off
    set verify off
    set echo off
    set feedback off
    -- any other sets needed
    select * from bigtable
    /'|sqlplus -s|grep -v ^$|sort -u> j$$2
    diff j$$1 j$$2
    rm j$$*I think I may have fed these into pipes and diff'd the pipes to avoid temp files, but I don't remember, it was like 10-20 years ago. There might be some way to tee the sqlplus output to two pipes which then do the differential sorts and feed pipes to diff, but I never tried that.
    Edit: I meant select unique identifier, not select *, of course.
    Edited by: jgarry on Jun 30, 2011 8:47 AM

  • The best way to find the relationship in table especially for PS

    Hi All,
    How the fastest way to find the relationship between PS table with another table.
    For example table PROJ, PRPS with another table in FICO module...let say the table that store the transaction CJR2...WBS element link to Cost element or activity type...and material on it...
    please help.
    Cheers,
    Nies

    go to se38 select any report then click radio button attribute and double on logical data base write PSJ as logical data base for Project and select display structure. You will get all dependant table name in relevant sequence

  • Looking for a way to find out the x,y coordinates of a string inside a PDF

    Hi!
    I'm looking for a way to find out the x,y coordinates of a string inside a PDF (with free java api's only)
    I got a pdf, and a string to find inside it, what i need to do is to get this string x,y position inside that pdf....
    If any one knows of such, plz let me know...
    Thanx ahead
    Daniel.

    vedmack wrote:
    Hi!
    I'm looking for a way to find out the x,y coordinates of a string inside a PDF (with free java api's only)
    I got a pdf, and a string to find inside it, what i need to do is to get this string x,y position inside that pdf....
    If any one knows of such, plz let me know...
    Thanx ahead
    Daniel.AFAIK, a string of text does not have an (x,y) location inside a PDF file. The location is exists on your screen, and will differ whenever you adjust the resolution of it. Text can have a location when it's stored as an image though, but than it's really the location of a certain number of pixels (not necessarily a string!).

  • I have lost my iPad 3 (3G). I do not use iCloud and I do not have the 'Find my iPad' app installed. What can I do to find it? Is there another way to bring up a map of where it is?

    Although I have Telstra 3G
    I do not use iCloud and I do not have the 'Find my iPad' app installed. What can I do to find it? Is there another way to bring up a map of where it is?
    I dont know the opperating system but I only got it recently...
    I also have a mac book pro also without iCloud.

    Without Find My iPad having been enabled on it then there isn't any way to locate it - and that would only work if it's connected to a network and hasn't been wiped or had Find My iPad disabled on it.
    If you think that it was stolen then you should report it to the police. You should also contact your carrier and change your iTunes account password, your email account passwords, and any passwords that you'd stored on websites/emails/notes etc.

  • Fastest way to remove html tags except url in href from string using java

    Hi All,
    Please suggest the, fastest way to remove html tags (stripe) except url in href of an anchor tag from string using java.
    Please help me with the best solution as I use parser but it's taking time to remove the html tags from string of file.
    I want the program should give the performance as 1 millisecond for 2kb file.
    Please help me out... Thanks in advance

    Hi,
    how can I replace the anchor tag in a string, by the url in the href of that anchor tag by using jsoup,
    e. g.
    <code>
    suppose input text is :
    test, string using, dsfg, 1:14 PM, < a t a r ge t="_ablank" s t y l e = " color: red" h r e f = " h t t p : / / t e s t u r l . c o m / i n d e x . j s p ? a = 1 2 3 4 " > s u p p o r t < / a >, s c h e d u l a r t a g , < a t a r g e t = " _ vbblank " s t y l e = " c o l o r : g r e e n " h r e f = " h t t p : / / t e s t u r l g r e e n . c o m / i n d e x . j s p ? a = a s d f a s df 4 " > s u pp o r t r e q < / a > a s d f pq r
    then out put text should be :
    test, string using, dsfg, 1:14 PM, http://testurl.com/index.jsp?a=1234, schedular tag, http://testurlgreen.com/index.jsp?a=asdfasdf4 asdf pqr
    </code>
    Please help at the earliest..
    Thanks in advance
    as this text editor is not supporting html anchor tag the example is not displaying correctly
    Edited by: 976815 on Dec 17, 2012 5:17 AM

  • Fastest way to access data between String and char[]

    Hi all,
    I've been programming a small String generator and was curious about the best and fastest way to do so.
    I've done it in two ways and now hope you can tell me if there is a "more java version" or fastest way between those two or if I'm totally wrong as some classe in the API already does that.
    Here are the codes:
    version 1:
            //describe the alphabet
         String alphabet = "abcdefghijklmnopqrstuvwxyz";
         //The "modifiable String"
         StringBuffer stringBuffer = new StringBuffer();
         //Just put the temporary int declaration outside the loop for performance reasons
         int generatedNumber;
         //Just do a "for" loop to get one letter and add it the String
         //Let's say we need a 8 letters word to be generated
         for (int i=0; i < 8; i++)
             generatedNumber = (int)(Math.random() * 26);
             stringBuffer.append(alphabet.charAt(generatedNumber));
         System.out.println(stringBuffer.toString());
         stringBuffer =null;version 2:
            //describe the alphabet
         char[] alphabetArray = {'a', 'b', 'c', 'd', 'e', 'f',
                        'g', 'h', 'i', 'j', 'k', 'l',
                        'm', 'n', 'o', 'p', 'q', 'r',
                        's', 't', 'u', 'v', 'w', 'x',
                        'y', 'z'}
         //The "modifiable String"
         StringBuffer stringBuffer = new StringBuffer();
         //Just put the temporary int declaration outside the loop for performance reasons
         int generatedNumber;
         //Just do a "for" loop to get one letter and add it the String
         //Let's say we need a 8 letters word to be generated
         for (int i=0; i < 8; i++)
             generatedNumber = (int)(Math.random() * 26);
             stringBuffer.append(alphabetArray[generatedNumber]);
         System.out.println(stringBuffer.toString());
         stringBuffer =null;Basically, the question is, what is the safest, fastest and more "to the rules" way to access a char in a sequence?
    Thanks in advance.
    Edited by: airchtit on Jan 22, 2008 6:02 AM

    paul.miner wrote:
    Better, use a char[] instead of a StringBuffer/StringBuilder, since you seem to know the size of the array in advance.
    Although I imagine making "alphabet" a char[] has slightly less overhead than making it a String
    1. It's a lot clearer to write it as a String.
    2. You can just call toCharArray() on the String to get a char[], instead of writing out each char individually.
    3. Or if you're going to be using a plain alphabet, just use (randomNumber + 'a')
    And use Random.nextInt()Hello and thx for the answers,
    I know I shouldn't put constants in my code, it was just a piece of code done in 1 minute to help a colleague.
    Even if it was just a one minute piece of code, I was wondering about the performance problem on large scale calculating, I mean something like a 25 characters word for billions of customers but anyway, once again, the impact should be minimal.
    By the way, I didn't know the Random Class (shame on me, I still don't know the whole API) and, I don't understand why I should be using this one more than the Random.Math which is static and thus take a few less memory and is easier to call.
    Is it because of the repartition factor?
    According to the API, the Random.Math gives (almost) a uniform distribution whether the Random.nextInt() gives a "more random" int.
    I

  • Fastest way to add spaces to a String?

    I need to have strings with a fixed width containing variable length text. The following (working) code does this with stupid if() and for() statements:
            StringBuffer levelName = new StringBuffer(record.getLevel().getName());
            if (levelName.length() < LEVEL_WIDTH) {
                int g = LEVEL_WIDTH - levelName.length();
                for (int i = 0; i < g; i++) {
                    levelName.append(' ');
            sb.append(levelName); As this code is called a lot of time, i'm looking for a more efficient way to expand strings to a fixed width (by adding spaces). is there a better performing solution?

    In this simple padding situation, there's no real advantage to using a StringBuffer over just a char array:
    //(1) do this once:
    char[] spaces = new char[LEVEL_WIDTH];
    char[] buffer = new char[LEVEL_WIDTH];
    java.util.Arrays.fill(spaces, ' ');
    //(2) Do this whenever you pad:
    int len = yourString.length();
    if (len < LEVEL_WIDTH) {
        System.arraycopy(yourString, 0, buffer, 0, len);
        System.arraycopy(spaces, 0, buffer, len, LEVEL_WIDTH-len);
        yourString = new String(buffer); //(*)
    }Notes:
    1. First off, it should be noted that trying to optimize before profiling could be a waste of time: what if the next operation is a database query that takes 100,000 times are long as this?
    2. arraycopy is a native op, so it should run faster than a loop. Arrays.fill calls arraycopy, btw.
    3. For efficiency, I reuse arrays buffer and spaces.
    4. The char array is copied in line (*). It would be nice to avoid that copying: to copy the original string and append padding directly into the strings buffer, but I don't see how that's possible. Using a StringBuffer involves at least as much copying, as far as I can tell (he says, staring at the source code)...

  • I lost my ipod touch, i know there is a way to find it through what i have purchased, i have an ipad as well, so i do not know if the system differenciates and how to do it

    I lost my IpodTouch; I know there is a way to find it as in a google map, but I do not know how, can someone tell me ?? I do not even have the ID for the ipod but through purchases in the i store, can I know and then look for it?

    In the source pane on the left click on "faces"
    You may want to watch the iphoto tutorials - https://ssl.apple.com/findouthow/photos/
    LN

  • HT4061 How do I refresh the Find My iPhone map now that they have "upgraded" the product? There is no longer a refresh button.

    Until this week there was a button next to the device identification that allowed you to refresh the Find My iPhone map.  That button is now gone and I cannot see a way to refresh the map without exiting and reentering Find My iPhone.  Any help would be appreciated.  Thank you.

    You need to go to the part where you see your device on the map and then there is a little refresh button next to the name of your device on the map page.

  • Fastest way to transfer information from my old MacBook Pro to a new one?

    What is fastest way to transfer data between MacBook pros? It takes forever on wi-if.

    Sometimes the fastest way would be just to transfer only your files via a external hard drive via drag and drop methods into the same named accounts on the new machine. This is especially useful if you want to avoid corruption of the old machine and have a chance to clean house of older files.
    By the time one fiddles around finding a Firewire cable and adpaters, a standard USB 3 external hard drive could be done already and be gotten at any local computer or office store.
    Also Retina's have SSD's and any data on them is not scrubbable like hard drives can be. Scrubbing SSD's would involve the entire drive being filled and this would wear them out prematurely as they have limited writes to each sector.
    If you want to use Migration or Setup Assistant, there is some element of risk involved because your copying the corruption over from the previous machine if it exists. If you know the previous software is fine on the older machine, then you can use Carbon Copy Cloner to clone the whole OS X boot parititon to the external USB drive, then hook this up to the new machine and run Migration/Setup Assistant against it, just like you would in Firewire Target Disk Mode if you don't want to wait to get a Thunderbolt to Firewire adpater from Apple.
    If you already have the Thunderbolt to Firewire adapter and a cable/adpater to the old Mac, then that's the fastest way.

  • Fastest way to create child class from parent?

    As the subject states, what do you folks find is fastest when creating child classes directly from the parent? (esp. when the parent is in a lvlib) I thought I'd post up and ask because the fastest way I've found to get working takes a few steps.
    Any suggestions ae appreciatized!
    -pat

    Thanks for the quick response Ben!
    Yea, I apologize, in your response I realize my OP was more than vague haha (it hapens when you get used to your own way of doing things I guess huh)- I'm trying to create a child from a parent so that it has all of the methods that the parent has.
    In order to do so I currently have to open and close LV a few times during my current process so that vi's in memory dont get mixed up- Currently I save a copy of the parent class in a sub dir of where it is saved, close out of LV, open the new 'copy of parent.lvclass', save as>>rename 'child class.lvclass', close LV, and open up the project to 'add file', then right click>>properties>>inheritance.
    Is this the only way to do this?
    Thanks again!
    -pat
    p.s. I'm tempted to steal your cell phone sig, hope you dont mind haha good stuff!

Maybe you are looking for

  • After Win 7 Pro 64 crash, CS6 AE, PS and PPro won't start.

    Windows 7 runs fine and LR 4.3 runs fine.  The CS apps mentioned above now will not start.  PS fails upon "measuring memory", AE and PPro get the splash screen then fail.  I reinstalled the CS6 applications to no avail.  My connected drives work fine

  • Unable to install os x (10.5.8) update from 10.5.4

    I've been trying to update my os from 10.5.4>10.5.8 with zero luck. After it apparently downloads restart occurs and once installation proceeds it freezes. I've tried leaving it for 20-30 minutes to see if that works-no avail. I've googled the proble

  • What is the use of REUSE_ALV_FIELDCATALOG_MERGE

    Hi in alv's what is the use of REUSE_ALV_FIELDCATALOG_MERGE OTHER THAN ADDING FIELD HEADINGS Title Edited by: Alvaro Tejada Galindo on Jan 11, 2008 4:20 PM

  • Need to reinstall OS X - Good Procedure to keep MAIL etc.

    If you ahve read my previous posts you have seen my problem. My solution? I need to reinstall OS X I used to have a procedure written up for this: What to back up first, how to keep my documents, my preferences, my MAIL (especially)... Is there a lin

  • Need Information For Connecting Access point to WLC 4402

    Hi Friends I need Some information for Connecting  my New Access point ( Cisco AIRLAP 1242AG) with WLC(4402) Controller In our network set up we have two WLC(4402) we needs to Connect this New Accesspoint To one of our WLC My Access point is brand Ne