You are given several logs that each log contains a unique id and timestamp. Timestamp is a string that has the following format: Year:Month:Day:Hour:Minute:Second, for example, 2017:01:01:23:59:59. All domains are zero-padded decimal numbers.

Design a log storage system to implement the following functions:

void Put(int id, string timestamp): Given a log's unique id and timestamp, store the log in your storage system.

int[] Retrieve(String start, String end, String granularity): Return the id of logs whose timestamps are within the range from start to end. Start and end all have the same format as timestamp. However, granularity means the time level for consideration. For example, start = "2017:01:01:23:59:59", end = "2017:01:02:23:59:59", granularity = "Day", it means that we need to find the logs within the range from Jan. 1st 2017 to Jan. 2nd 2017.

Example 1:

put(1, "2017:01:01:23:59:59");
put(2, "2017:01:01:22:59:59");
put(3, "2016:01:01:00:00:00");
retrieve("2016:01:01:01:01:01","2017:01:01:23:00:00","Year"); // return [1,2,3], because you need to return all logs within 2016 and 2017.
retrieve("2016:01:01:01:01:01","2017:01:01:23:00:00","Hour"); // return [1,2], because you need to return all logs start from 2016:01:01:01 to 2017:01:01:23, where log 3 is left outside the range.

Note:

  1. There will be at most 300 operations of Put or Retrieve.
  2. Year ranges from [2000,2017]. Hour ranges from [00,23].
  3. Output for Retrieve has no order required.
 class LogSystem {
List<String []> logs;
List<String> units = Arrays.asList("Year", "Month", "Day", "Hour", "Minute", "Second");
int [] indices = new int[]{,,,,,}; public LogSystem() {
logs = new LinkedList<String []>();
} public void put(int id, String timestamp) {
logs.add(new String[]{Integer.toString(id), timestamp});
} public List<Integer> retrieve(String s, String e, String gra) {
List<Integer> res = new ArrayList<Integer>();
int ind = indices[units.indexOf(gra)]; String sSub = s.substring(, ind);
String eSub = e.substring(, ind); for(String [] log : logs){
String sub = log[].substring(, ind);
if(sub.compareTo(sSub)>= && sub.compareTo(eSub)<=){
res.add(Integer.valueOf(log[]));
}
}
return res;
}
} /**
* Your LogSystem object will be instantiated and called as such:
* LogSystem obj = new LogSystem();
* obj.put(id,timestamp);
* List<Integer> param_2 = obj.retrieve(s,e,gra);
*/

Design Log Storage System的更多相关文章

  1. [LeetCode] Design Log Storage System 设计日志存储系统

    You are given several logs that each log contains a unique id and timestamp. Timestamp is a string t ...

  2. LeetCode Design Log Storage System

    原题链接在这里:https://leetcode.com/problems/design-log-storage-system/description/ 题目: You are given sever ...

  3. [leetcode-635-Design Log Storage System]

    You are given several logs that each log contains a unique id and timestamp. Timestamp is a string t ...

  4. Bigtable: A Distributed Storage System for Structured Data

    https://static.googleusercontent.com/media/research.google.com/en//archive/bigtable-osdi06.pdf Abstr ...

  5. Storage System and File System Courses

    I researched a lot about storage system classes given at good universities this year. This had two r ...

  6. 1.1 Introduction中 Kafka as a Storage System官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Kafka as a Storage System kafka作为一个存储系统 An ...

  7. Blockstack: A Global Naming and Storage System Secured by Blockchains

    作者:Muneeb Ali, Jude Nelson, Ryan Shea, and Michael Freedman Blockstack Labs and Princeton University ...

  8. f4: Facebook’s Warm BLOB Storage System——Erasure Code

    Facebook在OSDI 2014上发表论文f4: Facebook's Warm BLOB Storage System,这个系统主要目的就是降低存储成本,在容忍磁盘,主机,机架,数据中心的同时提 ...

  9. Bigtable:A Distributed Storage System for Strctured Data

    2006 年10 月Google 发布三架马车之一的<Bigtable:A Distributed Storage System for Strctured Data>论文之后,Power ...

随机推荐

  1. [Loj] 数列分块入门 1 - 9

    数列分块入门 1 https://loj.ac/problem/6277 区间加 + 单点查询 #include <iostream> #include <cstdio> #i ...

  2. kubernetes 的configMap和sercet配置信息

    简介: 启动pod,pod启动时可以将configMap资源关联到当前pod上来,从中读一个数据c传递给pod内的容器的一个变量.任然是变量注入的方式来给容器传配置信息. 把每一个configMap当 ...

  3. SPOJ AMR12B 720

    这个题应该是个优先队列的模版题 当时比赛的时候没时间做先贴一下大神的代码好好学习学习 B - Gandalf vs the Balrog Time Limit:2000MS     Memory Li ...

  4. ansiblle---roles

    使用ansible中的roles来管理主机. 剧本中的roles你现在已经学过 tasks 和 handlers,那怎样组织 playbook 才是最好的方式呢?简单的回答就是:使用 roles ! ...

  5. 3.JSON使用

    把 JSON 文本转换为 JavaScript 对象 JSON 最常见的用法之一,是从 web 服务器上读取 JSON 数据(作为文件或作为 HttpRequest),将 JSON 数据转换为 Jav ...

  6. 【Makefile】Makefile中的常用函数简介

    1. subst函数 格式:$(subst <from>, <to>, <text>)功能:把字串<text>中的<from>字符串替换成& ...

  7. 发布机制-灰度发布-例子:Windows

    ylbtech-发布机制-灰度发布-例子:Windows 在传统软件产品发布过程中(例如微软的Windows 7的发布过程中),一般都会经历Pre-Alpha.Alpha.Beta.Release c ...

  8. C# 批处理制作静默安装程序包

    使用批处理+WinRAR制作静默安装程序包 @echo 安装完窗口会自动关闭!!! @echo off start /wait Lync.exe /Install /Silent start /wai ...

  9. mysql 截取字符函数substring(param1,param2,param3) 的用法

    substring(paramter1,paramter2,paramter3) 截取字段长度 paramter1  被截取的字段paramter2 从第几位开始截取,负数表示从末尾开始数,的位数开始 ...

  10. Mac 配置vscode调试PHP

    Mac系统版本:MacOS Mojave  10.14.5 vscode:1.36.0 MacOS Mojave  10.14.5 系统自带 PHP 7.1.23 1.开启php sudo vim / ...