Skip to content
Browse files

Changed to use shorts instead of ints

  • Loading branch information...
1 parent f4c0c63 commit 9f96b3adc91c09883ec9a9bff47a4654461fdead @eljefe6a committed
Showing with 40 additions and 16 deletions.
  1. +36 −12 src/Node.java
  2. +4 −4 src/RollGraphWritable.java
View
48 src/Node.java
@@ -2,34 +2,58 @@
* Represents a single node in the graph.
*
* @author jesseanderson
- *
+ *
*/
public class Node {
/** The node's row in the roll */
- public int row;
+ public short row;
/** The node's column in the roll */
- public int column;
+ public short column;
/**
* Constructor
- * @param row The node's row in the roll
- * @param column The node's column in the roll
+ *
+ * @param row
+ * The node's row in the roll
+ * @param column
+ * The node's column in the roll
*/
- public Node(int row, int column) {
+ public Node(short row, short column) {
this.row = row;
this.column = column;
}
/**
- * Constructor
- * @param row The node's row in the roll
- * @param column The node's column in the roll
+ * Constructor that converts strings
+ *
+ * @param row
+ * The node's row in the roll
+ * @param column
+ * The node's column in the roll
*/
public Node(String row, String column) {
- this.row = Integer.parseInt(row);
- this.column = Integer.parseInt(column);
+ this.row = Short.parseShort(row);
+ this.column = Short.parseShort(column);
}
-
+
+ /**
+ * Constructor that converts ints to shorts
+ *
+ * @param row
+ * The node's row in the roll
+ * @param column
+ * The node's column in the roll
+ */
+ public Node(int row, int column) {
+ if (row > Short.MAX_VALUE || column > Short.MAX_VALUE) {
+ throw new RuntimeException("Row or column exceeds short. Row was " + row + " column was " + column
+ + " and both should be less than " + Short.MAX_VALUE);
+ }
+
+ this.row = (short) row;
+ this.column = (short) column;
+ }
+
@Override
public boolean equals(Object o) {
if (o instanceof Node) {
View
8 src/RollGraphWritable.java
@@ -48,8 +48,8 @@ public void write(DataOutput out) throws IOException {
// Write out the nodes
for (Node node : nodes) {
- out.writeInt(node.row);
- out.writeInt(node.column);
+ out.writeShort(node.row);
+ out.writeShort(node.column);
}
}
@@ -64,8 +64,8 @@ public void readFields(DataInput in) throws IOException {
// Read in the nodes
for (int i = 0; i < numNodes; i++) {
- int row = in.readInt();
- int column = in.readInt();
+ short row = in.readShort();
+ short column = in.readShort();
nodes.add(new Node(row, column));
}

0 comments on commit 9f96b3a

Please sign in to comment.
Something went wrong with that request. Please try again.