in Education by
Is there a data structure that implements the Map interface and holds an array of elements with continuous integer keys efficiently in Java? In my view, to achieve best efficiency, it would be equivalent to wrapping an array or ArrayList with an index offset value in a Map interface, or a hash table with the hash function f(key) = key - offset and a minimum backing array. I know this is quite simple but I don't want to reinvent the wheels. Is there such a data structure in JDK? Or is there a library that provides an implementation? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
If you don't need to support updates (which would make your problem a lot harder), consider passing in an IntFunction to specify the mapping instead of a Map When you have a Map, you can pass map::get, and when you don't have a map, you have a lots of easy ways to specify a mapping. For example, you can use a lambda to define a simple mapping function like: IntFunction mapper = v -> { if (v < offset || v >= offset+array.length) return null; return array[v-offset]; }

Related questions

0 votes
    I tried to convert data from the list of strings into a Map with the Stream API. But the way I ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 3, 2022 in Education by JackTerrance
0 votes
    Which of these method is used to remove all keys/values pair from the invoking map? (a) delete() (b) ... Collections Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    Which of these methods can be used to obtain set of all keys in a map? (a) getAll() (b) getKeys( ... The Collections Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    Which of these method is used to remove all keys/values pair from the invoking map? (a) delete() ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    Which of these methods can be used to obtain set of all keys in a map? (a) getAll() (b) ... java programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    Which 2 elements best describe the elements of Continuous Deployment (CD)...
asked Nov 30, 2020 in Technology by Editorial Staff
0 votes
    A __________ is a set of elements appearing in rows and columns where the elements are of the same mode whether ... of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    How to synchronize List, Set and Map elements?...
asked May 27, 2021 in Technology by JackTerrance
0 votes
    I have a 2 column (1 int and 1 double) dataframe "fit_comparison", of predicted values and linear ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    List numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    List numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    I have one column in my table which will store data in string format the sample data is {"pre- ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    I would like to know the relation between the mapreduce.map.memory.mb and mapred.map.child.java.opts parameters. ... .child.java.opts? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    What is the difference between Set and Map in JAVA?...
asked May 26, 2021 in Technology by JackTerrance
0 votes
    What is the purpose of map method of stream in Java 8?...
asked Nov 8, 2020 in Education by Editorial Staff
...