473,385 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.

Expand|Select|Wrap|Line Numbers
  1. import java.io.File;
  2. import java.io.*;
  3. import java.util.*;
  4. import java.util.Arrays;
  5.  
  6. public class d3
  7. {
  8.     public static void main (String[] args) throws Exception
  9.     {
  10.         FileReader fr;
  11.         try
  12.         {
  13.              fr = new FileReader(args[0]);
  14.         }
  15.         catch (FileNotFoundException e)
  16.         {
  17.             System.out.println("File Not Found.");
  18.             return;
  19.         }
  20.         Scanner sc = new Scanner(fr);
  21.         while (sc.hasNextLine())
  22.         {
  23.         int[] phone_num = new int[8000000];
  24.         String[] phone_num_str;
  25.         phone_num_str = new String[8000000];
  26.         phone_num_str  = sc.nextLine();
  27.         phone_num_str = phone_num_file;
  28.         phone_num = Integer.parseInt(phone_num_str);
  29.         }
  30.     }
  31. }
  32.  

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!
Feb 10 '11 #1
6 5313
horace1
1,510 Expert 1GB
for a start you need an index to the arrays, e.g.
Expand|Select|Wrap|Line Numbers
  1.         phone_num_str[index]  = sc.nextLine();
  2.  
also I would move the definition of the arrays outside the loop otherwise they get recreated each loop
Feb 10 '11 #2
Rabbit
12,516 Expert Mod 8TB
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.
Feb 10 '11 #3
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?...
Feb 10 '11 #4
Rabbit
12,516 Expert Mod 8TB
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.
Feb 10 '11 #5
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...
Feb 10 '11 #6
Rabbit
12,516 Expert Mod 8TB
It would help if you could post the prompt given by the instructor.
Feb 10 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Michael B. Trausch | last post by:
I have a question regarding bitwise operators, I've been trying to figure this out for about two days now, and I just can't seem to get it. What I'm trying to do is use a variable to hold a bitmask...
11
by: Randell D. | last post by:
Why would one use bitwise operators? I can program in various languages in some shape or form (C++, PHP, some scripting) and I've heard/seen bitwise operators before, but never understood why...
4
by: Mike Hodkin | last post by:
As a beginning student of C++, books reference "bitwise operators" and give brief examples, but I have not read a good explanation of what they are used for. One reference mentioned that they are...
12
by: sandy_pt_in | last post by:
How to mulitply two integer numbers using bitwise operators in C language.Please reply as early as possible
6
by: jas_lx | last post by:
The basic understanding of what bitwise operators (& ^ | >> << ) comes fairly simple, as long as one has a fundamental understanding of bits, bytes and binary. Having done some Win32...
37
by: James Radke | last post by:
Hello, I found some code that I could use in my application on the web, but it is written in C#, and I would like to convert it to VB. And I am having problems with one section. Is there...
3
by: shdwsclan | last post by:
I am native to various languages but bitwise operators just kill me. I see how much I take object oriented languages for granted. I like all the other c derivitives but ANSI C is making me loose my...
5
by: noridotjabi | last post by:
I'm learning to program in C and any tutorial or book that I read likes to briefly touch on birdies operators and then move on without giving any sort of example application of them. Call me what...
29
by: Carl Banks | last post by:
Anyone with me here? (I know the deadline for P3 PEPs has passed; this is just talk.) Not many people are bit-fiddling these days. One of the main uses of bit fields is flags, but that's not...
16
by: Santhosh | last post by:
Hi to all, How the individual digits of a number can be obtained using the bitwise operators alone.Is it possible to do it ? If we have n = 34 Result has to be 3,4. Thanks a billion for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.