Commit f7af321f8dada36485cfcfa17e47fa9e99d9cf9e

Authored by joel ago
1 parent 0394859f2e
Exists in master

UTILS DEPENDENCY 추가

Showing 3 changed files with 2 additions and 58 deletions Side-by-side Diff

app/com/piki_ds/utils/hbase/Base62.scala View file @ f7af321
1   -package com.piki_ds.utils.hbase
2   -
3   -import java.util.Date
4   -
5   -/**
6   - * Created by jihoonkang on 5/15/15.
7   - */
8   -
9   -
10   -object Base62 {
11   - val base62 = new Base62()
12   -
13   - def decode(s:String) = {
14   - base62.decode(s)
15   - }
16   - def encode(i:Long) = {
17   - base62.encode(i)
18   - }
19   -
20   - def main(args:Array[String]) = {
21   - //println(Base62.encode(99642))
22   - println(new Date(Base62.decode("P8to8Y4")))
23   - }
24   -}
25   -
26   -class Base62(baseString: String = ((0 to 9) ++ ('A' to 'Z') ++ ('a' to 'z')).mkString) {
27   -
28   - val base = 62
29   -
30   - def using[A, R <: { def close() }](r: R)(f: R => A): A =
31   - try { f(r) } finally { r.close() }
32   -
33   - if (baseString.size != base) {
34   - throw new IllegalArgumentException("baseString length must be %d".format(base))
35   - }
36   -
37   - def decode(s: String): Long = {
38   - s.zip(s.indices.reverse)
39   - .map { case (c, p) => baseString.indexOf(c) * scala.math.pow(base, p).toLong }
40   - .sum
41   - }
42   -
43   - def encode(i: Long): String = {
44   -
45   - @scala.annotation.tailrec
46   - def div(i: Long, res: List[Int] = Nil): List[Int] = {
47   - (i / base) match {
48   - case q if q > 0 => div(q, (i % base).toInt :: res)
49   - case _ => i.toInt :: res
50   - }
51   - }
52   -
53   - div(i).map(x => baseString(x)).mkString
54   - }
55   -
56   -}
app/com/piki_ds/utils/hbase/PikiHbase.scala View file @ f7af321
... ... @@ -3,7 +3,6 @@
3 3 import java.text.SimpleDateFormat
4 4 import java.util.Date
5 5  
6   -import com.piki_ds.utils.hbase.Base62
7 6 import org.apache.hadoop.hbase.io.compress.Compression.Algorithm
8 7 import org.apache.hadoop.hbase.{HColumnDescriptor, TableName, HTableDescriptor}
9 8 import org.apache.hadoop.hbase.client._
... ... @@ -39,7 +39,8 @@
39 39 "io.spray" %% "spray-routing" % sprayV,
40 40 "io.spray" %% "spray-client" % sprayV,
41 41 "org.apache.hbase" % "hbase-client" % "0.98.6-hadoop2",
42   - "org.apache.hbase" % "hbase-common" % "0.98.6-hadoop2"
  42 + "org.apache.hbase" % "hbase-common" % "0.98.6-hadoop2",
  43 + "com.piki_ds" %% "dsutils" % "0.1.0-SNAPSHOT"
43 44 )
44 45  
45 46