나는 사람들이 다음과 같은 속성을 저장하는 메모리에 큰 정적 데이터 세트가 검색 :스토어 모든 문자열 배열의 조합
[성별, 연령, 인종, 결혼 지위, 교육, 기본 국가, workclass을 , occupation]
각 특성은 미리 정의 된 값 집합에서 값을 가져 오며 각 특성에 대해 크기가 다릅니다. 다음 사전입니다.
[[남성, 여성], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, , 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 8081828384858687888990,91,92 , 93, 94, 95, 96, 97, 98, 99, 100], [백인, 아시아계 애호가, Amer-Indian-Eskimo, 기타, 검정], [결혼 한 배우자, 이혼, 결혼하지 않은 배우자 없음, 결혼 한 AF 배우자], [학사, 일부 대학, 11 학년, HS-grad, Prof-school, Assoc-acdm, Assoc-voc, 9 일, 7-8 일, 12 일 (미국, 캄보디아, 잉글랜드, 푸에르토 리코, 캐나다, 독일, 외딴 지역 (괌 -USVI 등), 인도, 일본, 그리스, 소 에콰도르, 대만, 아이티, 콜롬비아, 헝가리, 과테말라, 니카라과, 스코틀랜드, 콜롬비아, 에콰도르, 카리브해, 태국, 유고 슬라비아, El-Salvador, Trinadad & Tobago, Peru, Hong, Holand-Netherlands], [자체, 자체 emp-inc, 자체 emp-inc, 연방 정부, 지방 정부, 기술 지원, 공예 - 수리, 기타 서비스, 영업, 경영 - 관리, 전문 - 특수 기술, 처리기 - 청소기, 기계 - 작동기, Adm-clerical, 농어업, Privilege-Serv, Protective-serv, Armed-Forces]]
가능한 모든 조합을 유지하는 구조가있어서 데이터 집합의 각 조합에 대해 일부 통계를 저장할 수 있습니다. 예 특정 조합이 데이터 집합에 몇 번 존재하는지), 데이터 집합에 존재하지 않는 조합에 대해서도 일부 정보를 저장합니다. 그래서 모든 조합이 표현되어야합니다.
ArrayList [] 의 ArrayList를 사용하여 가능한 모든 조합을 만들려고했지만 몇 초가 걸리고 indexOf (x)를 사용하여 특정 조합을 검색합니다. 여기서 x는 String []이 작동하지 않는 것 같습니다.
public class Grid {
// Immutable fields
private final int combinationLength;
private final String[][] values;
private final int[] maxIndexes;
private final ArrayList<String[]> GridValues = new ArrayList<String[]>();
// Mutable fields
private final int[] currentIndexes;
private boolean hasNext;
public Grid(final String[][] array) {
combinationLength = array.length;
values = array;
maxIndexes = new int[combinationLength];
currentIndexes = new int[combinationLength];
if (combinationLength == 0) {
hasNext = false;
return;
}
hasNext = true;
// Fill in the arrays of max indexes and current indexes.
for (int i = 0; i < combinationLength; ++i) {
if (values[i].length == 0) {
// Set hasNext to false if at least one of the value-arrays is empty.
// Stop the loop as the behavior of the iterator is already defined in this case:
// the iterator will just return no combinations.
hasNext = false;
return;
}
maxIndexes[i] = values[i].length - 1;
currentIndexes[i] = 0;
}
while (hasNext()){
String[] nextCombination = next();
GridValues.add(nextCombination);
}
}
private boolean hasNext() {
return hasNext;
}
public String[] next() {
if (!hasNext) {
throw new NoSuchElementException("No more combinations are available");
}
final String[] combination = getCombinationByCurrentIndexes();
nextIndexesCombination();
return combination;
}
private String[] getCombinationByCurrentIndexes() {
final String[] combination = new String[combinationLength];
for (int i = 0; i < combinationLength; ++i) {
combination[i] = values[i][currentIndexes[i]];
}
return combination;
}
private void nextIndexesCombination() {
for (int i = combinationLength - 1; i >= 0; --i) {
if (currentIndexes[i] < maxIndexes[i]) {
// Increment the current index
++currentIndexes[i];
return;
} else {
// Current index at max:
// reset it to zero and "carry" to the next index
currentIndexes[i] = 0;
}
}
// If we are here, then all current indexes are at max, and there are no more combinations
hasNext = false;
}
}
누구나 더 빠르고 더 좋은 방법은 무엇입니까?
고맙습니다.
예제 코드가 있습니까? 원하는 것을 이해하는 것은 정말 어렵습니다. – Blobonat
원하는 모든 데이터 조합을 생성하는 방법은 여러 가지가 있습니다. 아무도 다른 것보다 빠릅니다. 왜 이것을 필요로합니까? 그리고 SQLite와 같은 것을 통해 이익을 얻을 수 있습니까? –
@ Yazan 제 목표는 데이터 세트에 특정 조합이 몇 번 존재 하는지를 아는 것입니다.하지만 결국에는 '잡음'을 추가하고 존재하지 않는 원소도 0이 아닌 값을 갖습니다. – ikro