|
|
-
Two questions about GenericArray in the Java implementation
Jeff Hammerbacher 2010-05-20, 01:16
1) Why does size() return a long instead of an int? java.util.List, for example, returns an int. Not returning an int leads to a lot of lint. 2) Why is there no get(index i) method? I can get an iterator and continually call next(), but sometimes you want to look up a single element by index.
My apologies if these are dumb questions; I know very little about Java.
Thanks, Jeff
-
RE: Two questions about GenericArray in the Java implementation
Scott Carey 2010-05-20, 01:27
1) I think the intent was to support avro arrays with more than 2 billion elements eventually. Additionally the underlying serialized array size in the avro spec is a long, not an int. 2) We could add something to get items by index but it could only work on small arrays that are not streamed. I don't think the Generic interface supports streaming large arrays yet anyway.
Generally, most users will loop over an array using the Java 5 syntax that hides the iterator creation and get() call:
GenericArray<SomeType> array;
for (SomeType item : array) { doSomething(item); }
Rather than something like for (i = 0; i < size; i++) { SomeType item = array.get(i); doSomething(item); }
-Scott -----Original Message----- From: Jeff Hammerbacher [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 19, 2010 6:16 PM To: [EMAIL PROTECTED] Subject: Two questions about GenericArray in the Java implementation
1) Why does size() return a long instead of an int? java.util.List, for example, returns an int. Not returning an int leads to a lot of lint. 2) Why is there no get(index i) method? I can get an iterator and continually call next(), but sometimes you want to look up a single element by index.
My apologies if these are dumb questions; I know very little about Java.
Thanks, Jeff
-
Re: Two questions about GenericArray in the Java implementation
Doug Cutting 2010-05-20, 19:13
On 05/19/2010 06:16 PM, Jeff Hammerbacher wrote: > 2) Why is there no get(index i) method? I can get an iterator and > continually call next(), but sometimes you want to look up a single element > by index.
An array could in theory be larger than fits in memory, so random access should perhaps not be encouraged. That said, the only implementation of this interface, GenericData.Array, is entirely in memory. Probably we should at least add a get(int) method to that class.
Doug
|
|
All projects made searchable here are trademarks of the Apache Software Foundation.
Service operated by
Sematext