String->Integer Hashmap alternative

by al capwn » Fri, 10 Apr 2009 22:17:04 GMT


Sponsored Links
 Currently, I'm using a hashmap which maps strings to integers. I've read
that using a wrapper for a primitive type in a hashmap has extra cost and
was wandering if there is an alternative I could use.

I've seen sparsearrays in the sdk, but they map ints to objects but I need
the opposite. Is there an alternative to hashmap available for this or
should I write my own class to use an array of strings and a seperate array
of ints? If I do write my own class, is there a better implementation I
could do?

--~--~---------~--~----~------------~-------~--~----~



String->Integer Hashmap alternative

by Streets Of Boston » Fri, 10 Apr 2009 22:23:04 GMT


 If you mean you map 'String's to 'int's, then yes, you have some
overhead because of the autoboxing of Java, making 'int's into
'Integer's.

If your map's keys (in this case Strings) can be any possible String,
i would just use a Map<String, Integer>.

Depending on how you use this map, you should create a TreeMap or a
HashMap. TreeMap is more expensive in modifying itself, but fast in
reading. HashMap is more expensive in reading, but faster in modifying
itself.

I don't know what your requirements are, but, in general, i would not
advice you to write your own Map implementation.




--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Fwd: How to Build Shelves application via Eclipse on Windows

Hi Romain Guy,

Don't know if this is the appropriate forum to ask this question.

Please redirect if it is not the appropriate forum.

What is the appropriate IDE/OS combination to build the Shelves project
located via link below.

I attempted to build the Shelves application via Windows XP using Eclipse
Ganymede 3.4:

http://code.google.com/p/shelves/

I checked out project via SVN (using subclipse plugin client for Eclipse) as
a project in workspace.

I am able to build other Eclipse Android based projects via SVN in similar
manner with no issue.

I am unable to build project.  I tried to convert the project into an
Android Project by selecting
[Android Tools]-->[Convert To Android Project] option via Eclipse but the
operation fails
with
  Error Msg:    <failed to get output folder>

I also tried to build the project from commandline using Ant with no
success.

Any assistance is truly welcomed.

Regards,

K

--~--~---------~--~----~------------~-------~--~----~

2. Goldfish Kernel 2.6.27 problem for emulator

Hi
 I was trying to upgrade the kernel image for emulator from 2.6.25 to
2.6.27.

I took the gold fish code and compiled as per the goldfish_defconfig file.

Loading the new kernel images gives me the following problem.

can anybody help ? It will be even better if some body from the android
team answer this question !!!

The complete log of -show-kernel is given below

Note : when i revert back to the old kernel everything works properly.

Regards
Joe



Uncompressing
Linux.....................................................................................
done, booting the kernel.
emulator: emulator window was out of view and was recentred
Linux version 2.6.27 (r...@ubuntu810desktop) (gcc version 4.3.1 (GCC) ) #1
Thu Feb 26 22:16:35 IST 2009
CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00003137
Machine: Goldfish
Memory policy: ECC disabled, Data cache writeback
CPU0: D VIVT write-through cache
CPU0: I cache: 4096 bytes, associativity 4, 32 byte lines, 32 sets
CPU0: D cache: 65536 bytes, associativity 4, 32 byte lines, 512 sets
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 24384
Kernel command line: qemu=1 console=ttyS0 android.checkjni=1
android.qemud=ttyS1 android.ndns=1
Unknown boot option `android.checkjni=1': ignoring
Unknown boot option `android.qemud=ttyS1': ignoring
Unknown boot option `android.ndns=1': ignoring
PID hash table entries: 512 (order: 9, 2048 bytes)
Console: colour dummy device 80x30
Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
Memory: 96MB = 96MB total
Memory: 94040KB available (2412K code, 640K data, 104K init)
Calibrating delay loop... 563.60 BogoMIPS (lpj=2818048)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
net_namespace: 288 bytes
NET: Registered protocol family 16
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 4096 (order: 3, 32768 bytes)
TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
TCP reno registered
NET: Registered protocol family 1
checking if image is initramfs... it is
Freeing initrd memory: 133K
goldfish_new_pdev goldfish_interrupt_controller at ff000000 irq -1
goldfish_new_pdev goldfish_device_bus at ff001000 irq 1
goldfish_new_pdev goldfish_timer at ff003000 irq 3
goldfish_new_pdev goldfish_rtc at ff010000 irq 10
goldfish_new_pdev goldfish_tty at ff002000 irq 4
goldfish_new_pdev goldfish_tty at ff011000 irq 11
goldfish_new_pdev smc91x at ff012000 irq 12
goldfish_new_pdev goldfish_fb at ff013000 irq 13
goldfish_new_pdev goldfish_audio at ff004000 irq 14
goldfish_new_pdev goldfish_memlog at ff006000 irq -1
goldfish_new_pdev goldfish-battery at ff014000 irq 15
goldfish_new_pdev goldfish_events at ff015000 irq 16
goldfish_new_pdev goldfish_nand at ff016000 irq -1
goldfish_new_pdev goldfish-switch at ff017000 irq 17
goldfish_new_pdev goldfish-switch at ff018000 irq 18
goldfish_pdev_worker registered goldfish-switch
goldfish_pdev_worker registered goldfish-switch
goldfish_pdev_worker registered goldfish_nand
goldfish_pdev_worker registered goldfish_events
goldfish_pdev_worker registered goldfish-battery
goldfish_pdev_worker registered goldfish_memlog
goldfish_pdev_worker registered goldfish_audio
goldfish_pdev_worker registered goldfish_fb
goldfish_pdev_worker registered smc91x
goldfish_pdev_worker registered goldfish_tty
goldfish_pdev_worker registered goldfish_tty
goldfish_pdev_worker registered goldfish_rtc
goldfish_pdev_worker registered goldfish_timer
goldfish_pdev_worker registered goldfish_device_bus
goldfish_pdev_worker registered goldfish_interrupt_controller
goldfish_audio_probe
ashmem: initialized
Installing knfsd (copyright (C) 1996 o...@monad.swb.de).
yaffs Feb 26 2009 22:13:35 Installing.
msgmni has been set to 184
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
allocating frame buffer 320 * 480, got ffc10000
Console: switching to colour frame buffer device 40x30
console [ttyS0] enabled
brd: module loaded
loop: module loaded
nbd: registered device at major 43
logger: created 64K log 'log_main'
logger: created 256K log 'log_events'
logger: created 64K log 'log_radio'
smc91x.c: v1.1, sep 22 2004 by Nicolas Pitre <n...@cam.org>
eth0: SMC91C11xFD (rev 1) at c6800000 IRQ 12 [nowait]
eth0: Ethernet addr: 52:54:00:12:34:56
goldfish nand dev0: size 4000000, page 2048, extra 64, erase 131072
goldfish nand dev1: size 4000000, page 2048, extra 64, erase 131072
goldfish nand dev2: size 4000000, page 2048, extra 64, erase 131072
mice: PS/2 mouse device common for all mice
events_probe() addr=0xc6804000 irq=16
events_probe() keymap=qwerty2
input: qwerty2 as /devices/virtual/input/input0
GRE over IPv4 tunneling driver
TCP cubic registered
NET: Registered protocol family 17
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
802.1Q VLAN Support v1.8 Ben Greear <gree...@candelatech.com>
All bugs added by David S. Miller <da...@redhat.com>
VFP support v0.3: implementor 41 architecture 1 part 10 variant 9 rev 0
goldfish_rtc goldfish_rtc: setting system clock to 2009-02-27 00:27:05 UTC
(1235694425)
Freeing init memory: 104K

init: Unable to open persistent property directory /data/property errno: 2

init: cannot find '/system/bin/sh', disabling 'console'

init: cannot find '/system/bin/mountd', disabling 'mountd'

init: cannot find '/system/bin/rild', disabling 'ril-daemon'
init: cannot find '/system/bin/app_process', disabling 'zygote'

init: cannot find '/system/bin/playmp3', disabling 'bootsound'
init: cannot find '/system/bin/dbus-daemon', disabling 'dbus'

init: cannot find '/system/bin/flash_image', disabling 'flash_recovery'
init: cannot find '/system/etc/init.goldfish.sh', disabling 'goldfish-setup'
init: cannot find '/system/bin/qemud', disabling 'qemud'
init: cannot find '/system/bin/logcat', disabling 'goldfish-logcat'

Regards
Joe

--~--~---------~--~----~------------~-------~--~----~

3. using an android project with google code hosting

4. ./pvplayer_engine_test: permission denied "

5. How to unsign and resign the apk file?

6. Porting to Samsung's ARMs

7. Implementing inherited abstract methods