内存 大文件
比如有一个文件ABC 56
DEF 100
RET 300
...
文件有2列,第一列都是不重复的,第2列表示次数(当成一个数字就行了)。
如果文件大小为2G或者更大,内存只有1G的情况,如何快速定位到“ABC 56” 这一行。
请大拿们给个清晰点的解决方法。
回复讨论(解决方案)
没明白您是什么意思?
如果是打开文件想快速找到某一行的话,可以使用vi或者more将文件打开;
然后输入: /ABC 回车就好了
fopen,再fscanf。
一次读一行就好啊。内存不会成为限制因素的。
有没有人知道啊?
如果是一行一行读,那效率就不行啦。
还有没有更快速的方法呢?
我的思路是建一张哈希表,然后根据哈希算法,再用那个哈希碰撞的原理去排重。
不知道各位有什么好的意见没
建hash表的话,岂不是要先对文件的内容进行hash?
可以用其他的工具来处理,未必一定要用算法。
比如awk:
awk '/ABC\t56/{ print NR}' file
可以获取匹配行的行号。
建议lz说下具体的需求,如果仅仅是获取行号的话,方案很多。
但是如果还有其他需求的话,类似awk这么做未必是最佳方案。
有没有人知道啊?
如果是一行一行读,那效率就不行啦。
还有没有更快速的方法呢?
我的思路是建一张哈希表,然后根据哈希算法,再用那个哈希碰撞的原理去排重。
不知道各位有什么好的意见没 那你不也得先一行一行读出来再哈希吗?
嫌一行一行读太慢,可以一块一块读
有没有人知道啊?
如果是一行一行读,那效率就不行啦。
还有没有更快速的方法呢?
我的思路是建一张哈希表,然后根据哈希算法,再用那个哈希碰撞的原理去排重。
不知道各位有什么好的意见没 那你不也得先一行一行读出来再哈希吗?
嫌一行一行读太慢,可以一块一块读
是的读块 比较符合你的需求
楼主可参考:
http://www.fantxi.com/blog/archives/php-read-large-file/
http://sjolzy.cn/php-large-file-read-operation.html
建hash表的话,岂不是要先对文件的内容进行hash?
可以用其他的工具来处理,未必一定要用算法。
比如awk:
awk '/ABC\t56/{ print NR}' file
可以获取匹配行的行号。
建议lz说下具体的需求,如果仅仅是获取行号的话,方案很多。
但是如果还有其他需求的话,类似awk这么做未必是最佳方案。
需求就是怎么能快速找到? 比如我想知道ABC后面的数字,或者DEF后面的数字...
有没有人知道啊?
如果是一行一行读,那效率就不行啦。
还有没有更快速的方法呢?
我的思路是建一张哈希表,然后根据哈希算法,再用那个哈希碰撞的原理去排重。
不知道各位有什么好的意见没 那你不也得先一行一行读出来再哈希吗?
嫌一行一行读太慢,可以一块一块读
内存怎么一块一块读呢? 能给个例子吗?

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!
