Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 流式JSON算法-无堆栈_Algorithm_Streaming_Stack - Fatal编程技术网

Algorithm 流式JSON算法-无堆栈

Algorithm 流式JSON算法-无堆栈,algorithm,streaming,stack,Algorithm,Streaming,Stack,是否可以设计一种流式JSON算法,将JSON直接写入具有以下属性的套接字: * can only write to, but cannot delete or seek within the stream * does not use either an IMPLICIT or explicit stack * uses only a constant amount of memory stack depth no matter how deep the object nesting withi

是否可以设计一种流式JSON算法,将JSON直接写入具有以下属性的套接字:

* can only write to, but cannot delete or seek within the stream
* does not use either an IMPLICIT or explicit stack
* uses only a constant amount of memory stack depth no matter how deep the object nesting within the json
{“1”:{“1”:{“1”:{“1”:{“1”:{“1”:{“1”:{“1”:{“1”:{“1”:{“1”:{“1”:{“1”:{“1”:{“1”:{……}}

简短回答:否


稍微长一点:至少在一般情况下不是这样。如果可以保证嵌套没有分支,那么可以使用一个简单的计数器关闭末尾的大括号。

否,因为可以使用这样的程序将无限量的内存压缩到有限的空间中

编码实现:
不这不是家庭作业。我正在用ruby编写一个web应用程序,但我不想使用to_json方法为什么不呢?你到底为什么会有这些荒谬的限制?试图拥有最小的状态和最小的内存,特别是在处理流数据时,是一件好事。一点也不荒谬。谢谢你的回答。你能给我指出任何计算机科学论文/形式语言理论文章(例如,上下文无关语法,BCNF)表明这一点吗?
input = read('LIBRARY_OF_CONGRESS.tar.bz2')
input_binary = convert_to_binary(input)
json_opening = replace({'0':'[', '1':'{'}, input_binary)
your_program <INPUTPIPE >/dev/null
INPUTPIPE << json_opening
set_output_pipe(your_program, OUTPUTPIPE)
INPUTPIPE << EOL
json_closing << OUTPUTPIPE
output_binary = replace({']':'0', '}':'1'}, reverse(json_closing))
output = convert_from_binary(output_binary)
write(output, 'LIBRARY_OF_CONGRESS-copy.tar.bz2')
bc 'LIBRARY_OF_CONGRESS.tar.bz2' 'LIBRARY_OF_CONGRESS-copy.tar.bz2'