[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-lib/master] Store relay flags more efficiently.
commit be359c873a456f6e6de34f9bb94ba97a545d3568
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Tue Jun 17 22:09:57 2014 +0200
Store relay flags more efficiently.
---
.../descriptor/impl/NetworkStatusEntryImpl.java | 26 +++++++++++++++++---
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java b/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
index d8aa5f0..e652a98 100644
--- a/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
+++ b/src/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
@@ -3,8 +3,11 @@
package org.torproject.descriptor.impl;
import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.SortedMap;
@@ -136,10 +139,24 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
this.orAddresses.add(parts[1]);
}
+ private static Map<String, Integer> flagIndexes =
+ new HashMap<String, Integer>();
+ private static Map<Integer, String> flagStrings =
+ new HashMap<Integer, String>();
+
private void parseSLine(String line, String[] parts)
throws DescriptorParseException {
this.parsedAtMostOnceKeyword("s");
- this.flags = parts;
+ BitSet flags = new BitSet(flagIndexes.size());
+ for (int i = 1; i < parts.length; i++) {
+ String flag = parts[i];
+ if (!flagIndexes.containsKey(flag)) {
+ flagStrings.put(flagIndexes.size(), flag);
+ flagIndexes.put(flag, flagIndexes.size());
+ }
+ flags.set(flagIndexes.get(flag));
+ }
+ this.flags = flags;
}
private void parseVLine(String line, String[] parts)
@@ -269,12 +286,13 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
return new ArrayList<String>(this.orAddresses);
}
- private String[] flags;
+ private BitSet flags;
public SortedSet<String> getFlags() {
SortedSet<String> result = new TreeSet<String>();
if (this.flags != null) {
- for (int i = 1; i < this.flags.length; i++) {
- result.add(this.flags[i]);
+ for (int i = this.flags.nextSetBit(0); i >= 0;
+ i = this.flags.nextSetBit(i + 1)) {
+ result.add(flagStrings.get(i));
}
}
return result;
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits