How to bitmaps and bitwise operators to sort and remove duplicates in a file?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Naz
    New Member
    • Feb 2011
    • 3

    How to bitmaps and bitwise operators to sort and remove duplicates in a file?

    I have to write a program to demonstrate using bitmaps and bitwise operators to sort and remove duplicates
    from a file of random phone numbers. a lot of them...

    im not new to programming and i want to really understand this so i was wondering i put up my code could i get some constuctive feed back about what might be wrong or missing from my approach. what i really dont want is the entire code just fed to me.. so in a lil while im gonna post what i got so far and hopefully someone will constuctively tear my code apart... just please be gental... hahaha :)

    The attached file is the 8,000,000 random phone number.

    Code:
    import java.io.File;
    import java.io.*;
    import java.util.*;
    import java.util.Arrays;
    
    public class d3
    {
    	public static void main (String[] args) throws Exception
    	{
    		FileReader fr;
    		try
    		{
    			 fr = new FileReader(args[0]);
    		}
    		catch (FileNotFoundException e)
    		{
    			System.out.println("File Not Found.");
    			return;
    		}
    		Scanner sc = new Scanner(fr);
    		while (sc.hasNextLine())
    		{
    		int[] phone_num = new int[8000000];
    		String[] phone_num_str;
    		phone_num_str = new String[8000000];
    		phone_num_str  = sc.nextLine();
    		phone_num_str = phone_num_file;
    		phone_num = Integer.parseInt(phone_num_str);
    		}
    	}
    }

    so, i know im missing a lot but i thought this would work at least but i was mistaken... im thinking it has to do with my while() arguement? im working on it but if theres an even bigger mistake (im sure there is) let me know.... thankz!
    Last edited by Niheel; Feb 10 '11, 07:25 AM.
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    for a start you need an index to the arrays, e.g.
    Code:
            phone_num_str[index]  = sc.nextLine();
    also I would move the definition of the arrays outside the loop otherwise they get recreated each loop

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      What do you mean by using bitmaps and bitwise operators to sort and remove duplicates? There's the bitap algorithm that's used to search for a string but it doesn't sort. There's the bloom filter algorithm that's used to find if something belongs to a set but that doesn't sort either. I don't know which algorithm you're referring to.

      Comment

      • Mike Naz
        New Member
        • Feb 2011
        • 3

        #4
        To be honnest im not entirely sure... i know i hate when people ask a question but don't know what they really are asking and im doing just that!! sorry.... but the idea is to open the file of the 8,000,000 phone numbers and assign them to an array (i think of ints---> later converted to bytes)

        im supposed to define a bitmap as an array of 1,000,000 bytes (that is, the type byte). Each bit in the array of one million bytes will represent one phone number. The bit will be turned on if and only if the number
        was read from the file. Those bits that remain off will indicate the number was never found in the file.

        so i think i understand that for each set of phonenumbers im gonna test (IF) each number is that number and if so it becomes... like 1 and if not it stays zero?... and then if its still a zero test it for the next number.... but how do i set each number to zero or 1 and then test it again after that?...

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          Who's asking you to do this? And why do they want you to do it this particular way?

          Because all it sounds like right now if that the bit array is just being used to track progress and has no actual bearing on the search algorithm which would have to be defined.

          Comment

          • Mike Naz
            New Member
            • Feb 2011
            • 3

            #6
            This is an assignment for a class. were just learing about bitmaps and bitwise functions and i feel like im falling behind.... and apparently i am if i cant even explain the assignment correctly.. sorry...

            Comment

            • Rabbit
              Recognized Expert MVP
              • Jan 2007
              • 12517

              #7
              It would help if you could post the prompt given by the instructor.

              Comment

              Working...