简体   繁体   English

如何实现facebook / linkedin人名目录?

[英]How to implement facebook / linkedin people names directory?

Check - 检查-

  1. http://www.facebook.com/directory http://www.facebook.com/directory
  2. http://www.linkedin.com/directory/people-a http://www.linkedin.com/directory/people-a

Lets say I have a list of ids and names in a mysql table. 可以说我在mysql表中有一个ID和名称列表。 How should I go about sorting those names, creating a directory same as facebook/linkedin, with the data in mysql table. 我应该如何对这些名称进行排序,并使用mysql表中的数据创建与facebook / linkedin相同的目录。

How should I store my data in mysql or some other form ? 我应该如何以mysql或其他形式存储数据?

I also want to be able to add more names later. 我也希望以后可以添加更多名称。

If you just want to display sorted items then you can use order by clause 如果只想显示排序的项目,则可以使用order by子句

select ids, name from tbles order by name aesc

That said, it is not possible to have a permanently sorted database. 也就是说,不可能有一个永久排序的数据库。 The database storage does not allow that for the simple reason of storage optimization. 出于存储优化的简单原因,数据库存储不允许这样做。

To solve your problem, you can extract the data from MySql to a file, sort it by a field(name) and then use a web application to display it. 要解决您的问题,您可以将数据从MySql提取到文件中,按字段(名称)对它排序,然后使用Web应用程序显示它。 In this method you first would have to identify your sorting method. 在这种方法中,您首先必须确定您的排序方法。

The best sorting algorithms have the time complexity of O(NlogN) . 最佳排序算法的时间复杂度为O(NlogN) This is the lowest theoretically possible time achievable to sort data in a randomized array (that is an array where elements are likely in random order). 从理论上讲,这是对随机数组(即元素可能按随机顺序排列的数组)中的数据进行排序所需的理论上最短的时间。 Have a look famous algorithms QuickSort and MergeSort . 看看著名的算法QuickSortMergeSort Decide in basis of whether you want stable sort and your datatype. 根据是否要稳定排序和数据类型来确定。

If you can use Java then you can use Array API for pre-built sort or Collections sort and writing a comparator for alphabetical ordering (default is natural ordering - ASCII). 如果可以使用Java,则可以使用Array API进行预先构建的排序或Collections排序,并编写比较器以按字母顺序排序(默认为自然排序-ASCII)。

Now see for any patterns in your input. 现在查看输入中的所有模式。 If you know the pattern of the data in your array (like partially sorted, duplicate values), you can write your own version of MergeSort or QuickSort with minor modifications for faster sort. 如果您知道数组中数据的模式(例如部分排序的重复值),则可以编写自己的MergeSort或QuickSort版本,并进行较小的修改以加快排序速度。

After this step, if your ids are in millions, then the above algorithms should easily sort it in few minutes. 完成此步骤后,如果您的ID数以百万计,则上述算法应该可以在几分钟内轻松对其进行排序。 Otherwise for very large dataset(in billions)- you could either split the data and write distributed/parallel code with more machines/cores, or if you have time then just wait for hours(maybe days) on a regular machine. 否则,对于非常大的数据集(十亿),您可以拆分数据并用更多的机器/内核编写分布式/并行代码,或者如果您有时间,则可以在常规机器上等待几个小时(也许几天)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM