473,387 Members | 1,766 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,387 software developers and data experts.

Increasing array size

I am trying to implement a hash-table and I would like to rehash it when
it starts to fill up. I am implementing the hash-table with an array
of linked lists. Now for me to increase the size of the hash-table I
must create a new array twice the size of the one before but the array
only accepts an imediate number eg array[1000] and will not accept a
variable eg array[count]. Does anyone know how to solve this problem?
thanks...
Nov 14 '05 #1
6 4156
On 2004-11-30, Ioannis Hadjichambis <ha******@cs.man.ac.uk> wrote:
I am trying to implement a hash-table and I would like to rehash it when
it starts to fill up. I am implementing the hash-table with an array
of linked lists. Now for me to increase the size of the hash-table I
must create a new array twice the size of the one before but the array
only accepts an imediate number eg array[1000] and will not accept a
variable eg array[count]. Does anyone know how to solve this problem?
thanks...


Like you would use a dynamic array of a regular type, i.e. using malloc().

Greetings, Chris

--
Christian Staudenmayer
University of Ulm, Germany
cs****@gmail.com
Nov 14 '05 #2

"Ioannis Hadjichambis" <ha******@cs.man.ac.uk> wrote in message
news:co**********@wapping.cs.man.ac.uk...
I am trying to implement a hash-table and I would like to rehash it when
it starts to fill up. I am implementing the hash-table with an array
of linked lists. Now for me to increase the size of the hash-table I
must create a new array twice the size of the one before but the array
only accepts an imediate number eg array[1000] and will not accept a
variable eg array[count]. Does anyone know how to solve this problem?
thanks...


Try allocating memory dynamically using malloc() instead of declaring a
fixed array. If your hash-table needs to grow, you can use realloc() to grow
the allocated dataspace or move it to a place where sufficient memory can be
allocated.
Nov 14 '05 #3
In C this would require using malloc for the array allocation.

It you were writing this code in C++, this would be an easy problem to
solve using the STL map.

Deepa
--
http://www.EventHelix.com/EventStudio
EventStudio 2.5 - Generate Sequence Diagrams in PDF and MS Word

Nov 14 '05 #4
Ioannis Hadjichambis wrote:

I am trying to implement a hash-table and I would like to rehash it
when it starts to fill up. I am implementing the hash-table with an
array of linked lists. Now for me to increase the size of the
hash-table I must create a new array twice the size of the one
before but the array only accepts an imediate number eg array[1000]
and will not accept a variable eg array[count]. Does anyone know
how to solve this problem? thanks...


All done and available under GPL. See:

<http://cbfalconer.home.att.net/download/hashlib.zip>

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!

Nov 14 '05 #5
"Require"? ... "Easy"? Let me rephrase Deepa's answers.

"EventHelix.com" <ev********@gmail.com> wrote in message news:<11*********************@z14g2000cwz.googlegr oups.com>...
In C this would require using malloc for the array allocation.
"In C this is very simple to do with malloc()."
It you were writing this code in C++, this would be an easy problem to
solve using the STL map.


"In C++, many might do this by invoking an unneccessarily complicated
copyrighted library."

If you like C++, you're welcome to it (though not in this newsgroup)
but do let's not confuse the novice with misleading tone.

James
Nov 14 '05 #6
James Dow Allen wrote:
It you were writing this code in C++, this would be an easy problem
to solve using the STL map.


"In C++, many might do this by invoking an unneccessarily complicated
copyrighted library."

While this is not a C++ newsgroup, and hence this is off-topic, I'll
briefly note that map is (as of the 1998 standard) part of the C++
standard library.


Brian
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Bryan Rickard | last post by:
I wrote a simple program in VB6 to copy all the files from a directory on a CD-ROM to my hard disk. There are about 10 files, each about 30MB. The program uses Get and Put to get data from the...
100
by: jacob navia | last post by:
As everybody knows, C uses a zero delimited unbounded pointer for its representation of strings. This is extremely inefficient because at each query of the length of the string, the computer...
3
by: Nick | last post by:
I have found a class that compresses and uncompresses data but need some help with how to use part of it below is the deflate method which compresses the string that I pass in, this works OK. At...
15
by: Joe Lester | last post by:
I installed Postgres 7.4.1 on a dual processor G5 running Mac OS 10.3.2. I'm trying to increase the max_connections to 300 and running into some trouble. If anyone could shed some light, I'd...
6
by: sandyboy | last post by:
Hi, Please help me to solve this problem. My database size is 8 GB , 5GB of data file and 3GB of log file. I increased the size of datafile to 10GB and log file to 3.5 GB with 11GB and 4GB by 20...
4
by: Rahul B | last post by:
Hi, I was getting the error: sqlcode: -911 sqlstate: 40001 , which is "The maximum number of lock requests has been reached for the database." So i increased the locklist size to 200 from the...
3
by: eso40043 | last post by:
Hi guys, I've asked for help here once before with great results, I thought I'd try it again. (I'm on Ubuntu 6.06 with python 2.4. Xemacs as editor.) I have an image as a scipy array and...
0
by: wajedali | last post by:
hi......... i have problem in incresing and decreasing the component. I have a one main panel (i.e. i used as _basewindowPanel) in that again two panel in that two panel like wise.... ...
4
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
Visual Studio 2005, C# WinForms application: Here’s the question: How can I increase the standard 1 MB stack size of the UI thread in a C# WinForms application? Here’s why I ask: I’ve...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.